class Datamappify::Repository::UnitOfWork::PersistentStates
Tracks dirty entity attributes
Public Class Methods
new()
click to toggle source
# File lib/datamappify/repository/unit_of_work/persistent_states.rb, line 8 def initialize @pool = {} end
Public Instance Methods
attach(entity)
click to toggle source
Attaches an entity
@param entity [Entity]
@return [Entity]
# 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)
click to toggle source
Finds or attaches an entity
@param entity [Entity]
@return [Entity]
# 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)
click to toggle source
@param entity [Entity]
@param attrs (see Object#mark_as_dirty
)
@see Object#mark_as_dirty
@return (see Object#mark_as_dirty
)
# 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)
click to toggle source
Refreshes the states stored for an entity
@param entity [Entity]
@return [Entity]
# 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)
click to toggle source
Executes a block then reattaches the entity
@param entity [Entity]
@return [Entity]
# File lib/datamappify/repository/unit_of_work/persistent_states.rb, line 44 def update(entity, &block) find(entity) block.call attach(entity) end