Module: Mongoid::Dirty::ClassMethods
- Defined in:
- lib/mongoid/dirty.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#add_dirty_methods(name) ⇒ Object
Add the dynamic dirty methods.
Instance Method Details
#add_dirty_methods(name) ⇒ Object
Add the dynamic dirty methods. These are custom methods defined on a field by field basis that wrap the dirty attribute methods.
Example:
person = Person.new(:title => "Sir")
person.title = "Madam"
person.title_change # [ "Sir", "Madam" ]
person.title_changed? # true
person.title_was # "Sir"
person.reset_title!
245 246 247 248 249 250 |
# File 'lib/mongoid/dirty.rb', line 245 def add_dirty_methods(name) define_method("#{name}_change") { attribute_change(name) } define_method("#{name}_changed?") { attribute_changed?(name) } define_method("#{name}_was") { attribute_was(name) } define_method("reset_#{name}!") { reset_attribute!(name) } end |