Class: LB::Project::Registry
- Inherits:
-
Object
- Object
- LB::Project::Registry
show all
- Includes:
- Enumerable
- Defined in:
- lib/lb/project/registry.rb,
lib/lb/project/registry/registration.rb
Overview
Defined Under Namespace
Modules: Registration
Classes: KeyNotFoundError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(keys = {}) ⇒ Registry
Returns a new instance of Registry.
19
20
21
|
# File 'lib/lb/project/registry.rb', line 19
def initialize(keys = {})
@keys = keys
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key) ⇒ Object
53
54
55
|
# File 'lib/lb/project/registry.rb', line 53
def method_missing(key, *)
keys.fetch(key) { super }
end
|
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
10
11
12
|
# File 'lib/lb/project/registry.rb', line 10
def keys
@keys
end
|
Instance Method Details
#each(&block) ⇒ Object
23
24
25
26
|
# File 'lib/lb/project/registry.rb', line 23
def each(&block)
return to_enum unless block
keys.each_pair { |key, value| yield(key, value) }
end
|
#fetch(key) ⇒ Object
Also known as:
[]
32
33
34
35
36
37
38
39
40
|
# File 'lib/lb/project/registry.rb', line 32
def fetch(key)
raise ArgumentError, 'key cannot be nil' if key.nil?
keys.fetch(key.to_sym) do
return yield if block_given?
raise KeyNotFoundError, key
end
end
|
#key?(key) ⇒ Boolean
28
29
30
|
# File 'lib/lb/project/registry.rb', line 28
def key?(key)
!key.nil? && keys.key?(key.to_sym)
end
|
#register(key, value) ⇒ Object
47
48
49
|
# File 'lib/lb/project/registry.rb', line 47
def register(key, value)
keys[key] = value
end
|
#respond_to_missing?(key, include_private = false) ⇒ Boolean
43
44
45
|
# File 'lib/lb/project/registry.rb', line 43
def respond_to_missing?(key, include_private = false)
keys.key?(key) || super
end
|