Class: Dry::Core::Container::Registry
- Inherits:
-
Object
- Object
- Dry::Core::Container::Registry
- Defined in:
- lib/dry/core/container/registry.rb
Overview
Default registry for registering items with the container
Instance Method Summary collapse
-
#call(container, key, item, options) ⇒ Mixed
Register an item with the container to be resolved later.
- #factory ⇒ Object private
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
11 12 13 |
# File 'lib/dry/core/container/registry.rb', line 11 def initialize @_mutex = ::Mutex.new end |
Instance Method Details
#call(container, key, item, options) ⇒ Mixed
Register an item with the container to be resolved later
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dry/core/container/registry.rb', line 33 def call(container, key, item, ) key = key.to_s.dup.freeze @_mutex.synchronize do if container.key?(key) raise KeyError, "There is already an item registered with the key #{key.inspect}" end container[key] = factory.call(item, ) end end |