Module: DirtyAssociations::ClassMethods
- Defined in:
- lib/dirty_associations.rb
Instance Method Summary collapse
-
#monitor_association_changes(association) ⇒ Object
Creates methods that allows an
associationto be monitored.
Instance Method Details
#monitor_association_changes(association) ⇒ Object
Creates methods that allows an association to be monitored.
The association parameter should be a string or symbol representing the name of an association.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dirty_associations.rb', line 15 def monitor_association_changes(association) ids = "#{association.to_s.singularize}_ids" [association, ids].each do |name| define_method "#{name}=" do |value| attribute_will_change!(association.to_s) unless send(name) == value super(value) end define_method "#{name}_change" do changes[name] end define_method "#{name}_changed?" do changes.has_key?(association.to_s) end define_method "#{name}_previously_changed?" do previous_changes.has_key?(association.to_s) end end end |