Class: Scorpion::ChainHunter

Inherits:
Object
  • Object
show all
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

Attributes included from Scorpion

#instance, #logger

Instance Method Summary collapse

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

#scorpionsArray<Scorpion>

Returns scorpions to chain hunting calls to.

Returns:

  • (Array<Scorpion>)

    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

See Also:

  • Scorpion#hunt


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

#replicateObject

See Also:



32
33
34
# File 'lib/scorpion/chain_hunter.rb', line 32

def replicate
  self.class.new *scorpions.map( &:replicate )
end