Sha256: 3c1cdb82c5122da4e2c5782aa53a8a63cc2041aedd2e9d22a7383e525decdc19
Contents?: true
Size: 1.21 KB
Versions: 7
Compression:
Stored size: 1.21 KB
Contents
module Hanuman class Registry REGISTRY = {} unless defined? REGISTRY def create_or_update(label, builder) create(label, builder) ? true : update(label, builder) end def create(label, builder) return false if registered?(label) REGISTRY[label] = builder true end def update(label, new_definition) return false unless registered?(label) REGISTRY[label].merge!(new_definition) true end def registered?(label) REGISTRY.keys.include? label end def retrieve(label) REGISTRY[label].clone rescue nil end 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 def show() REGISTRY.dup ; end def clear!() REGISTRY.clear ; end def merge!(contents) REGISTRY.merge!(contents) ; end end GlobalRegistry = Registry.new unless defined? GlobalRegistry end
Version data entries
7 entries across 7 versions & 2 rubygems