Module: ActiveData::Model::Dirty::ClassMethods

Defined in:
lib/active_data/model/dirty.rb

Instance Method Summary collapse

Instance Method Details

#define_dirty(method, target = self) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_data/model/dirty.rb', line 56

def define_dirty(method, target = self)
  reflection = reflect_on_attribute(method)
  name = reflection ? reflection.name : method

  %w[changed? change will_change! was
     previously_changed? previous_change].each do |suffix|
    target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{method}_#{suffix}
        attribute_#{suffix} '#{name}'
      end
    RUBY
  end

  target.class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def restore_#{method}!
      restore_attribute! '#{name}'
    end
  RUBY
end

#dirty?Boolean

Returns:



76
77
78
# File 'lib/active_data/model/dirty.rb', line 76

def dirty?
  true
end