Class: Payload::Container
- Inherits:
-
Object
- Object
- Payload::Container
- Defined in:
- lib/payload/container.rb
Overview
Used for configuring and resolving dependencies.
Instance Method Summary collapse
-
#[](dependency) ⇒ Object
Resolves and returns dependency.
-
#decorate(dependency) {|Container| ... } ⇒ Object
Extends or replaces an existing dependency definition.
-
#export(*names) ⇒ DependencyList
private
Exports dependencies which can be imported into another container.
-
#factory(dependency) {|Container| ... } ⇒ Object
Defines a factory which can be used to instantiate the dependency.
-
#import(definitions) ⇒ Container
private
Import dependencies which were exported from another container.
-
#initialize(definitions = DefinitionList.new) ⇒ Container
constructor
private
Used internally by RailsLoader.
-
#service(dependency) {|Container| ... } ⇒ Object
Defines a service which can be fully resolved from the container.
Constructor Details
#initialize(definitions = DefinitionList.new) ⇒ Container
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 RailsLoader.
18 19 20 |
# File 'lib/payload/container.rb', line 18 def initialize(definitions = DefinitionList.new) @definitions = definitions end |
Instance Method Details
#[](dependency) ⇒ Object
Resolves and returns dependency.
60 61 62 |
# File 'lib/payload/container.rb', line 60 def [](dependency) @definitions.find(dependency).resolve(self) end |
#decorate(dependency) {|Container| ... } ⇒ Object
Extends or replaces an existing dependency definition.
27 28 29 |
# File 'lib/payload/container.rb', line 27 def decorate(dependency, &block) self.class.new(@definitions.decorate(dependency, block)) end |
#export(*names) ⇒ DependencyList
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.
Exports dependencies which can be imported into another container.
Used internally by MutableContainer. Use MutableContainer#export.
71 72 73 |
# File 'lib/payload/container.rb', line 71 def export(*names) @definitions.export(names) end |
#factory(dependency) {|Container| ... } ⇒ Object
Defines a factory which can be used to instantiate the dependency. Useful if some dependencies come from the container but others come from runtime state.
Resolving the dependency will return an object which responds to ‘new`. The `new` method will accept remaining dependencies and return the fully resolved dependency from the given block.
43 44 45 |
# File 'lib/payload/container.rb', line 43 def factory(dependency, &block) define dependency, FactoryResolver.new(block) end |
#import(definitions) ⇒ Container
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.
Import dependencies which were exported from another container.
Used internally by RailsLoader.
82 83 84 |
# File 'lib/payload/container.rb', line 82 def import(definitions) self.class.new @definitions.import(definitions) end |
#service(dependency) {|Container| ... } ⇒ Object
Defines a service which can be fully resolved from the container.
52 53 54 |
# File 'lib/payload/container.rb', line 52 def service(dependency, &block) define dependency, ServiceResolver.new(block) end |