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
-
#apply(*arguments, **keywords) ⇒ PartialInstance
Return a new factory with some of the arguments provided.
-
#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.
14 15 16 17 18 |
# File 'lib/payload/factory.rb', line 14 def initialize(container, block, decorators) @container = container @block = block @decorators = decorators end |
Instance Method Details
#apply(*arguments, **keywords) ⇒ PartialInstance
Return a new factory with some of the arguments provided. Remaining arguments can be provided by invoking #new on the returned instance. Chaining #apply is also possible. This can be useful for returning a factory where some of the dependencies are provided by the container, and the remainder are provided at runtime.
46 47 48 |
# File 'lib/payload/factory.rb', line 46 def apply(*arguments, **keywords) PartialInstance.new(self).apply(*arguments, **keywords) end |
#new(*arguments) ⇒ Object
Returns the instance defined by the factory definition block.
24 25 26 27 |
# File 'lib/payload/factory.rb', line 24 def new(*arguments) base = @block.call(@container, *arguments) @decorators.decorate(base, @container, *arguments) end |