Class: Scorpion::Hunt
- Inherits:
-
Object
- Object
- Scorpion::Hunt
- Extended by:
- Forwardable
- Defined in:
- lib/scorpion/hunt.rb
Overview
Captures state for a specific hunt so that constructor dependencies can be shared with child dependencies.
Defined Under Namespace
Classes: InitializerTrip, Trip
Attributes collapse
-
#arguments ⇒ Array<Object>
readonly
Positional arguments to pass to the initializer of #contract when found.
-
#block ⇒ #call
Block to pass to constructor of contract when found.
-
#contract ⇒ Class, ...
Contract being hunted for.
-
#scorpion ⇒ Scorpion
Scorpion used to fetch uncaptured dependency.
-
#trip ⇒ Trip
writeonly
The current hunting trip.
-
#trips ⇒ Array<Array>
writeonly
The stack of trips conducted by the hunt to help resolve child dependencies.
Instance Method Summary collapse
-
#fetch(contract, *arguments, &block) ⇒ Object
Hunt for additional dependency to satisfy the main hunt's contract.
-
#initialize(scorpion, contract, *arguments, &block) ⇒ Hunt
constructor
A new instance of Hunt.
-
#inject(object) ⇒ Scorpion::Object
Inject given
objectwith its expected dependencies. -
#spawn(klass, *arguments, &block) ⇒ Object
(also: #new)
Allow the hunt to spawn objects.
Constructor Details
Instance Attribute Details
#arguments ⇒ Array<Object> (readonly)
Returns positional arguments to pass to the initializer of #contract when found.
|
|
# File 'lib/scorpion/hunt.rb', line 53
|
#block ⇒ #call
Returns block to pass to constructor of contract when found.
|
|
# File 'lib/scorpion/hunt.rb', line 56
|
#contract ⇒ Class, ...
Returns contract being hunted for.
|
|
# File 'lib/scorpion/hunt.rb', line 50
|
#scorpion ⇒ Scorpion
Returns scorpion used to fetch uncaptured dependency.
35 36 37 |
# File 'lib/scorpion/hunt.rb', line 35 def scorpion @scorpion end |
#trip=(value) ⇒ Trip
Returns the current hunting trip.
45 46 47 |
# File 'lib/scorpion/hunt.rb', line 45 def trip @trip end |
#trips=(value) ⇒ Array<Array>
Returns the stack of trips conducted by the hunt to help resolve child dependencies.
40 41 42 |
# File 'lib/scorpion/hunt.rb', line 40 def trips @trips end |
Instance Method Details
#fetch(contract, *arguments, &block) ⇒ Object
Hunt for additional dependency to satisfy the main hunt's contract.
70 71 72 73 74 75 |
# File 'lib/scorpion/hunt.rb', line 70 def fetch( contract, *arguments, &block ) push contract, arguments, block execute ensure pop end |
#inject(object) ⇒ Scorpion::Object
Inject given object with its expected dependencies.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/scorpion/hunt.rb', line 80 def inject( object ) trip.object = object object.send :scorpion_hunt=, self object.injected_attributes.each do |attr| next if object.send "#{ attr.name }?" next if attr.lazy? object.send :inject_dependency, attr, fetch( attr.contract ) end object.send :on_injected object end |
#spawn(klass, *arguments, &block) ⇒ Object Also known as: new
Allow the hunt to spawn objects.
98 99 100 |
# File 'lib/scorpion/hunt.rb', line 98 def spawn( klass, *arguments, &block ) scorpion.spawn( self, klass, *arguments, &block ) end |