Class: Containable::Register
- Inherits:
-
Object
- Object
- Containable::Register
- Defined in:
- lib/containable/register.rb
Overview
Registers dependencies for future evaluation.
Constant Summary collapse
- SEPARATOR =
"."
Instance Method Summary collapse
- #call(key, value = nil, &block) ⇒ Object (also: #register)
-
#initialize(dependencies = Concurrent::Hash.new, separator: SEPARATOR) ⇒ Register
constructor
A new instance of Register.
- #namespace(name) ⇒ Object
Constructor Details
#initialize(dependencies = Concurrent::Hash.new, separator: SEPARATOR) ⇒ Register
Returns a new instance of Register.
10 11 12 13 14 15 |
# File 'lib/containable/register.rb', line 10 def initialize dependencies = Concurrent::Hash.new, separator: SEPARATOR @dependencies = dependencies @separator = separator @keys = [] @depth = 0 end |
Instance Method Details
#call(key, value = nil, &block) ⇒ Object Also known as: register
17 18 19 20 21 22 23 24 25 |
# File 'lib/containable/register.rb', line 17 def call key, value = nil, &block namespaced_key = namespacify key = "Dependency is already registered: #{key.inspect}." warn "Registration of value is ignored since block takes precedence." if value && block fail KeyError, if dependencies.key? namespaced_key dependencies[namespaced_key] = block || value end |
#namespace(name) ⇒ Object
29 30 31 32 33 |
# File 'lib/containable/register.rb', line 29 def namespace(name, &) keys.clear if depth.zero? keys.append name visit(&) end |