Class: Dry::Container::Registry
- Inherits:
-
Object
- Object
- Dry::Container::Registry
- Defined in:
- lib/dry/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
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
12 13 14 |
# File 'lib/dry/container/registry.rb', line 12 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
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dry/container/registry.rb', line 34 def call(container, key, item, ) key = key.to_s.dup.freeze @_mutex.synchronize do if container.key?(key) raise Error, "There is already an item registered with the key #{key.inspect}" end container[key] = factory.call(item, ) end end |