Class: Scorpion::ChainHunter
- Inherits:
-
Object
- Object
- Scorpion::ChainHunter
- Includes:
- Scorpion
- Defined in:
- lib/scorpion/chain_hunter.rb
Overview
Chains hunting calls to one or more managed scorpions.
Constant Summary
Constants included from Scorpion
VERSION, VERSION_NUMBER, VERSION_SUFFIX
Attributes collapse
-
#scorpions ⇒ Array<Scorpion>
Scorpions to chain hunting calls to.
Attributes included from Scorpion
Instance Method Summary collapse
- #execute(hunt) ⇒ Object
-
#initialize(*scorpions) ⇒ ChainHunter
constructor
A new instance of ChainHunter.
-
#prepare(&block) ⇒ Object
Prepare the scorpion for hunting.
- #replicate ⇒ Object
Methods included from Scorpion
#build_nest, #destroy, #fetch, fetch, #inject, instance, instance=, logger, logger=, #new, prepare, #reset, #spawn
Constructor Details
#initialize(*scorpions) ⇒ ChainHunter
Returns a new instance of ChainHunter.
19 20 21 |
# File 'lib/scorpion/chain_hunter.rb', line 19 def initialize( *scorpions ) @scorpions = scorpions end |
Instance Attribute Details
#scorpions ⇒ Array<Scorpion>
Returns scorpions to chain hunting calls to.
13 14 15 |
# File 'lib/scorpion/chain_hunter.rb', line 13 def scorpions @scorpions end |
Instance Method Details
#execute(hunt) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/scorpion/chain_hunter.rb', line 37 def execute( hunt ) # Try explicitly defined dependencies first scorpions.each do |hunter| begin return hunter.execute( hunt, true ) rescue UnsuccessfulHunt # rubocop:disable Lint/HandleExceptions end end # Then allow implicit scorpions.each do |hunter| begin return hunter.execute( hunt ) rescue UnsuccessfulHunt # rubocop:disable Lint/HandleExceptions end end unsuccessful_hunt hunt.contract end |
#prepare(&block) ⇒ Object
Prepare the scorpion for hunting.
25 26 27 28 29 |
# File 'lib/scorpion/chain_hunter.rb', line 25 def prepare( &block ) if top = scorpions.first top.prepare &block end end |
#replicate ⇒ Object
32 33 34 |
# File 'lib/scorpion/chain_hunter.rb', line 32 def replicate self.class.new *scorpions.map( &:replicate ) end |