Class: Clowne::Utils::Plan
- Inherits:
-
Object
- Object
- Clowne::Utils::Plan
- Defined in:
- lib/clowne/utils/plan.rb
Overview
:nodoc: all
Defined Under Namespace
Classes: TwoPhaseSet
Instance Method Summary collapse
- #add(type, declaration) ⇒ Object
- #add_to(type, id, declaration) ⇒ Object
- #declarations(reload = false) ⇒ Object
- #dup ⇒ Object
- #get(type) ⇒ Object
-
#initialize(registry) ⇒ Plan
constructor
A new instance of Plan.
- #remove(type) ⇒ Object
- #remove_from(type, id) ⇒ Object
- #set(type, declaration) ⇒ Object
Constructor Details
#initialize(registry) ⇒ Plan
Returns a new instance of Plan.
30 31 32 33 |
# File 'lib/clowne/utils/plan.rb', line 30 def initialize(registry) @registry = registry @data = {} end |
Instance Method Details
#add(type, declaration) ⇒ Object
35 36 37 38 |
# File 'lib/clowne/utils/plan.rb', line 35 def add(type, declaration) data[type] = [] unless data.key?(type) data[type] << declaration end |
#add_to(type, id, declaration) ⇒ Object
40 41 42 43 |
# File 'lib/clowne/utils/plan.rb', line 40 def add_to(type, id, declaration) data[type] = TwoPhaseSet.new unless data.key?(type) data[type][id] = declaration end |
#declarations(reload = false) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/clowne/utils/plan.rb', line 63 def declarations(reload = false) return @declarations if !reload && instance_variable_defined?(:@declarations) @declarations = registry.actions.flat_map do |type| value = data[type] next if value.nil? value = value.values if value.is_a?(TwoPhaseSet) value = Array(value) value.map { |v| [type, v] } end.compact end |
#dup ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/clowne/utils/plan.rb', line 77 def dup self.class.new(registry).tap do |duped| data.each do |k, v| duped.set(k, v.dup) end end end |
#get(type) ⇒ Object
49 50 51 |
# File 'lib/clowne/utils/plan.rb', line 49 def get(type) data[type] end |
#remove(type) ⇒ Object
53 54 55 |
# File 'lib/clowne/utils/plan.rb', line 53 def remove(type) data.delete(type) end |
#remove_from(type, id) ⇒ Object
57 58 59 60 61 |
# File 'lib/clowne/utils/plan.rb', line 57 def remove_from(type, id) return unless data[type] data[type].delete(id) end |
#set(type, declaration) ⇒ Object
45 46 47 |
# File 'lib/clowne/utils/plan.rb', line 45 def set(type, declaration) data[type] = declaration end |