Class: ViewModel::ActiveRecord::UpdateContext::ReleasePool
- Inherits:
-
Object
- Object
- ViewModel::ActiveRecord::UpdateContext::ReleasePool
- Defined in:
- lib/view_model/active_record/update_context.rb
Instance Method Summary collapse
- #claim_from_pool(key) ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize ⇒ ReleasePool
constructor
A new instance of ReleasePool.
- #release_all! ⇒ Object
- #release_to_pool(viewmodel, association_data) ⇒ Object
Constructor Details
#initialize ⇒ ReleasePool
Returns a new instance of ReleasePool.
34 35 36 37 38 |
# File 'lib/view_model/active_record/update_context.rb', line 34 def initialize # hash of { ViewModel::Reference => ReleaseEntry } for models # that have been released by nodes we've already visited @released_viewmodels = {} end |
Instance Method Details
#claim_from_pool(key) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/view_model/active_record/update_context.rb', line 49 def claim_from_pool(key) if (entry = @released_viewmodels.delete(key)) entry.claimed! entry.viewmodel end end |
#include?(key) ⇒ Boolean
40 41 42 |
# File 'lib/view_model/active_record/update_context.rb', line 40 def include?(key) @released_viewmodels.has_key?(key) end |
#release_all! ⇒ Object
56 57 58 |
# File 'lib/view_model/active_record/update_context.rb', line 56 def release_all! @released_viewmodels.each_value(&:release!) end |
#release_to_pool(viewmodel, association_data) ⇒ Object
44 45 46 47 |
# File 'lib/view_model/active_record/update_context.rb', line 44 def release_to_pool(viewmodel, association_data) @released_viewmodels[viewmodel.to_reference] = ReleaseEntry.new(viewmodel, association_data) end |