Module: Lotus::Entity::DirtyTracking
- Defined in:
- lib/lotus/entity/dirty_tracking.rb
Overview
Dirty tracking for entities
Instance Method Summary collapse
-
#changed? ⇒ TrueClass, FalseClass
Checks if the attributes were changed.
-
#changed_attributes ⇒ ::Hash
Getter for hash of changed attributes.
-
#initialize(attributes = {}) ⇒ Object
Override initialize process.
Instance Method Details
#changed? ⇒ TrueClass, FalseClass
Checks if the attributes were changed
69 70 71 |
# File 'lib/lotus/entity/dirty_tracking.rb', line 69 def changed? changed_attributes.any? end |
#changed_attributes ⇒ ::Hash
Getter for hash of changed attributes. Return empty hash, if there is no changes Getter for hash of changed attributes. Value in it is the previous one.
60 61 62 |
# File 'lib/lotus/entity/dirty_tracking.rb', line 60 def changed_attributes Hash[@_initial_state.to_a - to_h.to_a] end |
#initialize(attributes = {}) ⇒ Object
Override initialize process.
32 33 34 35 |
# File 'lib/lotus/entity/dirty_tracking.rb', line 32 def initialize(attributes = {}) super @_initial_state = Utils::Hash.new(to_h).deep_dup end |