class Scorpion::Hunter

A concrete implementation of a Scorpion used to hunt down food for a {Scorpion::Object}. @see Scorpion

Attributes

dependency_map[R]

@return [Scorpion::DependencyMap] map of {Dependency} and how to create instances.

parent[R]

@return [Scorpion] parent scorpion to deferr hunting to on missing dependency.

Public Class Methods

new( parent = nil, &block ) click to toggle source

@!endgroup Attributes

# File lib/scorpion/hunter.rb, line 22
def initialize( parent = nil, &block )
  @parent         = parent
  @dependency_map = Scorpion::DependencyMap.new( self )

  prepare &block if block_given?
end

Public Instance Methods

execute( hunt, explicit_only = false ) click to toggle source

@see Scorpion#execute

# File lib/scorpion/hunter.rb, line 52
def execute( hunt, explicit_only = false )
  dependency   = find_dependency( hunt )
  dependency ||= Dependency.define( hunt.contract ) unless explicit_only

  unsuccessful_hunt( hunt.contract ) unless dependency

  dependency.fetch hunt
end
find_dependency( hunt ) click to toggle source

Find any explicitly defined dependencies that can satisfy the hunt. @param [Hunt] hunt being resolved. @return [Dependency] the matching dependency if found

# File lib/scorpion/hunter.rb, line 64
def find_dependency( hunt )
  dependency   = dependency_map.find( hunt.contract )
  dependency ||= parent.find_dependency( hunt ) if parent

  dependency
end
inspect() click to toggle source

@return [String]

# File lib/scorpion/hunter.rb, line 77
def inspect
  dependencies = dependency_map.to_a
  result = "<#{ self.class.name } contracts=#{ dependencies.inspect }"
  result << " parent=#{ parent.inspect }" if parent
  result << ">"
  result
end
prepare( &block ) click to toggle source

Prepare the scorpion for hunting. @see DependencyMap#chart

# File lib/scorpion/hunter.rb, line 31
def prepare( &block )
  dependency_map.chart &block
end
replicate() click to toggle source

@see Scorpion#replicate

# File lib/scorpion/hunter.rb, line 45
def replicate
  replica = self.class.new self
  replica.dependency_map.replicate_from( dependency_map )
  replica
end
reset() click to toggle source

@see Scorpion#reset

# File lib/scorpion/hunter.rb, line 72
def reset
  dependency_map.reset
end