Class: ViewModel::ActiveRecord::UpdateContext::ReleasePool

Inherits:
Object
  • Object
show all
Defined in:
lib/view_model/active_record/update_context.rb

Instance Method Summary collapse

Constructor Details

#initializeReleasePool

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

Returns:

  • (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