Class: Redundancy::UpdateMethodWithPrev
- Inherits:
-
UpdateBase
- Object
- UpdateBase
- Redundancy::UpdateMethodWithPrev
- Defined in:
- lib/redundancy/update_method_with_prev.rb
Instance Attribute Summary
Attributes inherited from UpdateBase
#change_if, #dest, #klass, #options, #source
Instance Method Summary collapse
Methods inherited from UpdateBase
Constructor Details
This class inherits a constructor from Redundancy::UpdateBase
Instance Method Details
#after_save(record) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/redundancy/update_method_with_prev.rb', line 15 def after_save record return unless need_update? record set_context :update_method, :update_column get_target_from_association record get_value_from_target record update_target record return unless context(:"target_prev") get_value_from_target record, :prev update_target record, :prev ensure cleanup_context end |
#before_save(record) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/redundancy/update_method_with_prev.rb', line 7 def before_save record raise_if_class_mismatch record return unless foreign_key_changed? record get_target_from_foreign_key record, :prev get_target_from_relation_first_record :prev end |