Class: Datamappify::Repository::UnitOfWork::PersistentStates
- Inherits:
-
Object
- Object
- Datamappify::Repository::UnitOfWork::PersistentStates
- Defined in:
- lib/datamappify/repository/unit_of_work/persistent_states.rb,
lib/datamappify/repository/unit_of_work/persistent_states/object.rb
Overview
Tracks dirty entity attributes
Defined Under Namespace
Classes: Object
Instance Method Summary collapse
-
#attach(entity) ⇒ Entity
Attaches an entity.
-
#find(entity) ⇒ Entity
Finds or attaches an entity.
-
#initialize ⇒ PersistentStates
constructor
A new instance of PersistentStates.
- #mark_as_dirty(entity, *attributes) ⇒ void
-
#refresh(entity) ⇒ Entity
Refreshes the states stored for an entity.
-
#update(entity, &block) ⇒ Entity
Executes a block then reattaches the entity.
Constructor Details
#initialize ⇒ PersistentStates
Returns a new instance of PersistentStates.
8 9 10 |
# File 'lib/datamappify/repository/unit_of_work/persistent_states.rb', line 8 def initialize @pool = {} end |
Instance Method Details
#attach(entity) ⇒ Entity
Attaches an entity
35 36 37 |
# File 'lib/datamappify/repository/unit_of_work/persistent_states.rb', line 35 def attach(entity) @pool[entity.object_id] = Object.new(entity) end |
#find(entity) ⇒ Entity
Finds or attaches an entity
17 18 19 |
# File 'lib/datamappify/repository/unit_of_work/persistent_states.rb', line 17 def find(entity) @pool.has_key?(entity.object_id) ? refresh(entity) : attach(entity) end |
#mark_as_dirty(entity, *attributes) ⇒ void
This method returns an undefined value.
59 60 61 |
# File 'lib/datamappify/repository/unit_of_work/persistent_states.rb', line 59 def mark_as_dirty(entity, *attributes) find(entity).mark_as_dirty(*attributes) end |
#refresh(entity) ⇒ Entity
Refreshes the states stored for an entity
26 27 28 |
# File 'lib/datamappify/repository/unit_of_work/persistent_states.rb', line 26 def refresh(entity) @pool[entity.object_id].tap { |o| o.update_values(entity) } end |
#update(entity, &block) ⇒ Entity
Executes a block then reattaches the entity
44 45 46 47 48 49 50 |
# File 'lib/datamappify/repository/unit_of_work/persistent_states.rb', line 44 def update(entity, &block) find(entity) block.call attach(entity) end |