Module: Granite::Form::Model::Dirty::ClassMethods

Defined in:
lib/granite/form/model/dirty.rb

Instance Method Summary collapse

Instance Method Details

#define_dirty(method, target = self) ⇒ Object



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

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:



77
78
79
# File 'lib/granite/form/model/dirty.rb', line 77

def dirty?
  true
end