Module: CanHasState::DirtyHelper::ClassMethods
- Defined in:
- lib/can_has_state/dirty_helper.rb
Instance Method Summary collapse
Instance Method Details
#track_dirty(*attrs) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/can_has_state/dirty_helper.rb', line 11 def track_dirty(*attrs) define_attribute_methods attrs attrs.each do |attr| attr = attr.to_s attr_reader(attr) unless respond_to?(attr) has_writer = respond_to?("#{attr}=") define_method "#{attr}=" do |val| send("#{attr}_will_change!") unless val == send(attr) has_writer ? super(val) : instance_variable_set("@#{attr}", val) changed_attributes.delete(attr) if attribute_was(attr) == send(attr) end end end |