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)


36
37
38
39
# File 'lib/sparkle_formation/utils.rb', line 36

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



54
55
56
57
58
59
60
# File 'lib/sparkle_formation/utils.rb', line 54

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



45
46
47
# File 'lib/sparkle_formation/utils.rb', line 45

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