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 |
# 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!(ids) super(value) end end define_method "#{ids}_changed?" do changed.include?(ids) end define_method "#{ids}_previously_changed?" do previous_changes.keys.include?(ids) end end |