3 def self.included(base)
4 base.extend ClassMethods
5 base.alias_method_chain :attributes_with_quotes, :changed
6 base.alias_method_chain :write_attribute, :changed
7 base.alias_method_chain :save, :changed
8 base.alias_method_chain :save!, :changed
9 base.alias_method_chain :reload, :changed
13 def lazy_attributes(*args)
14 @@lazy_attributes ||= Array(args).map(&:to_s).to_set
20 def attributes_with_quotes_with_changed(include_primary_key = true, include_readonly_attributes = true)
21 original = attributes_with_quotes_without_changed(include_primary_key, include_readonly_attributes)
23 # Reject only if both supplied arguments are false
24 original.reject! { |key, value| changed_lazy.include?(key) } if !(include_primary_key || include_readonly_attributes)
28 def write_attribute_with_changed(attr_name, value)
29 changed_lazy.delete(attr_name.to_s)
30 write_attribute_without_changed(attr_name, value)
33 def reload_with_changed
35 reload_without_changed
39 @changed_lazy ||= self.class.lazy_attributes.clone
43 save_without_changed ensure @changed_lazy = nil
46 def save_with_changed!
47 save_without_changed! ensure @changed_lazy = nil
52 ActiveRecord::Base.send :include, ActiveRecord::Changed