Class: Krikri::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Singleton
Defined in:
lib/krikri/registry.rb

Overview

Provide a registry of defined items that can be looked up by a token symbol.

Expected to be extended as needed within other modules.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry


18
19
20
# File 'lib/krikri/registry.rb', line 18

def initialize
  @items = {}
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items


15
16
17
# File 'lib/krikri/registry.rb', line 15

def items
  @items
end

Class Method Details

.get(name) ⇒ Object


24
25
26
27
# File 'lib/krikri/registry.rb', line 24

def get(name)
  raise "#{name} is not registered." unless registered? name
  instance[name]
end

.keysObject


42
43
44
# File 'lib/krikri/registry.rb', line 42

def keys
  instance.items.keys
end

.register(name, item) ⇒ Object


29
30
31
32
# File 'lib/krikri/registry.rb', line 29

def register(name, item)
  raise "#{name} is already registered." if registered? name
  register!(name, item)
end

.register!(name, item) ⇒ Object


34
35
36
# File 'lib/krikri/registry.rb', line 34

def register!(name, item)
  instance[name] = item
end

.registered?(name) ⇒ Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/krikri/registry.rb', line 38

def registered?(name)
  instance.items.keys.include? name
end