Class: Hanuman::Registry
- Inherits:
-
Object
- Object
- Hanuman::Registry
- Defined in:
- lib/hanuman/registry.rb
Constant Summary collapse
- REGISTRY =
{}
Instance Method Summary collapse
- #clear! ⇒ Object
- #create(label, builder) ⇒ Object
- #create_or_update(label, builder) ⇒ Object
- #decorate_with_registry(graph_instance) ⇒ Object
- #merge!(contents) ⇒ Object
- #registered?(label) ⇒ Boolean
- #retrieve(label) ⇒ Object
- #show ⇒ Object
- #update(label, new_definition) ⇒ Object
Instance Method Details
#clear! ⇒ Object
41 |
# File 'lib/hanuman/registry.rb', line 41 def clear!() REGISTRY.clear ; end |
#create(label, builder) ⇒ Object
10 11 12 13 14 |
# File 'lib/hanuman/registry.rb', line 10 def create(label, builder) return false if registered?(label) REGISTRY[label] = builder true end |
#create_or_update(label, builder) ⇒ Object
6 7 8 |
# File 'lib/hanuman/registry.rb', line 6 def create_or_update(label, builder) create(label, builder) ? true : update(label, builder) end |
#decorate_with_registry(graph_instance) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/hanuman/registry.rb', line 30 def decorate_with_registry(graph_instance) REGISTRY.each_pair do |label, definition| graph_instance.define_singleton_method(label) do |*args, &blk| builder = Hanuman::GlobalRegistry.retrieve(label) builder = handle_dsl_arguments_for(builder, *args, &blk) stages[builder.label] = builder end end end |
#merge!(contents) ⇒ Object
42 |
# File 'lib/hanuman/registry.rb', line 42 def merge!(contents) REGISTRY.merge!(contents) ; end |
#registered?(label) ⇒ Boolean
22 23 24 |
# File 'lib/hanuman/registry.rb', line 22 def registered?(label) REGISTRY.keys.include? label end |
#retrieve(label) ⇒ Object
26 27 28 |
# File 'lib/hanuman/registry.rb', line 26 def retrieve(label) REGISTRY[label].clone rescue nil end |
#show ⇒ Object
40 |
# File 'lib/hanuman/registry.rb', line 40 def show() REGISTRY.dup ; end |
#update(label, new_definition) ⇒ Object
16 17 18 19 20 |
# File 'lib/hanuman/registry.rb', line 16 def update(label, new_definition) return false unless registered?(label) REGISTRY[label].merge!(new_definition) true end |