Module: Exchanger::Dirty::ClassMethods

Defined in:
lib/exchanger/dirty.rb

Overview

:nodoc:

Instance Method Summary collapse

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!

230
231
232
233
234
235
236
# File 'lib/exchanger/dirty.rb', line 230

def add_dirty_methods(name)
  name = name.to_s
  define_method("#{name}_change") { attribute_change(name) } unless instance_methods.include?("#{name}_change")
  define_method("#{name}_changed?") { attribute_changed?(name) } unless instance_methods.include?("#{name}_changed?")
  define_method("#{name}_was") { attribute_was(name) } unless instance_methods.include?("#{name}_was")
  define_method("reset_#{name}!") { reset_attribute!(name) } unless instance_methods.include?("reset_#{name}!")
end