Class: SparkleFormation::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/sparkle_formation/utils.rb

Overview

Registry helper

Class Method Summary collapse

Class Method Details

.init!self

Initialize registry

Returns:

  • (self)


72
73
74
75
# File 'lib/sparkle_formation/utils.rb', line 72

def init!
  @register = AttributeStruct.hashish.new
  self
end

.insert(name, location, *args) ⇒ Object

Insert registry item into context

Parameters:

  • name (String, Symbol)

    name of item

  • location (AttributeStruct)

    context to apply block

  • args (Object)

    argument list for block



90
91
92
93
94
95
96
# File 'lib/sparkle_formation/utils.rb', line 90

def insert(name, location, *args)
  if block = @register[name]
    location.instance_exec(*args, &block)
  else
    raise KeyError.new("Requested item not found in registry (#{name})")
  end
end

.register(name) { ... } ⇒ Object

Register block

Parameters:

  • name (String, Symbol)

    name of item

Yields:

  • block to register



81
82
83
# File 'lib/sparkle_formation/utils.rb', line 81

def register(name, &block)
  @register[name] = block
end