Skip to content

Instantly share code, notes, and snippets.

@jmorton
Created September 27, 2011 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmorton/1246416 to your computer and use it in GitHub Desktop.
Save jmorton/1246416 to your computer and use it in GitHub Desktop.
Passive Record
# 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