Class: Payload::Factory
- Inherits:
-
Object
- Object
- Payload::Factory
- Defined in:
- lib/payload/factory.rb
Overview
Returned by Container#[] for Container#factory definitions.
Used to add definitions from #new to the Container and then run the factory definition block to obtain an instance.
Instance Method Summary collapse
-
#initialize(container, block, decorators) ⇒ Factory
constructor
private
Used internally by FactoryResolver.
-
#new(arguments = {}) ⇒ Object
The instance defined by the factory definition block.
Constructor Details
#initialize(container, block, decorators) ⇒ Factory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Used internally by Payload::FactoryResolver.
12 13 14 15 16 |
# File 'lib/payload/factory.rb', line 12 def initialize(container, block, decorators) @container = container @block = block @decorators = decorators end |
Instance Method Details
#new(arguments = {}) ⇒ Object
Returns the instance defined by the factory definition block.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/payload/factory.rb', line 22 def new(arguments = {}) resolved = arguments.inject(@container) do |container, (argument, value)| container.service(argument) { value } end base = @block.call(resolved) @decorators.decorate(base, resolved) end |