module NoBrainer::Document::Dirty::ClassMethods

Public Instance Methods

field(attr, options={}) click to toggle source
Calls superclass method
# File lib/no_brainer/document/dirty.rb, line 83
def field(attr, options={})
  super
  attr = attr.to_s

  inject_in_layer :dirty_tracking do
    define_method("#{attr}_change") do
      if @_old_attributes.key?(attr)
        result = [@_old_attributes[attr], _read_attribute(attr)]
        result if result.first != result.last || !@_old_attributes_keys.include?(attr)
      end
    end

    define_method("#{attr}_changed?") do
      !!__send__("#{attr}_change")
    end

    define_method("#{attr}_was") do
      @_old_attributes.key?(attr) ? @_old_attributes[attr] : _read_attribute(attr)
    end
  end
end
remove_field(attr, options={}) click to toggle source
Calls superclass method
# File lib/no_brainer/document/dirty.rb, line 105
def remove_field(attr, options={})
  super
  inject_in_layer :dirty_tracking do
    remove_method("#{attr}_change")
    remove_method("#{attr}_changed?")
    remove_method("#{attr}_was")
  end
end