Created
September 27, 2011 22:13
-
-
Save jmorton/1246416 to your computer and use it in GitHub Desktop.
Passive Record
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PassiveRecord disables all of the mutable behaviors of a class that behaves like an ActiveRecord::Base | |
module PassiveRecord | |
module Base | |
extend ActiveSupport::Concern | |
module InstanceMethods | |
def passive_record_benign_method(*args, &block) | |
return false | |
end | |
end | |
module ClassMethods | |
def passive_record_benign_class_method(*args, &block) | |
return false | |
end | |
end | |
included do | |
ActiveRecord::Persistence.instance_methods.each do |method_name| | |
alias_method method_name, :passive_record_benign_method | |
end | |
class << self | |
%w(create create! delete delete_all destroy destroy_all update).each do |method_name| | |
alias_method method_name, :passive_record_benign_class_method | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment