Class: Detroit::Toolchain::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/detroit/toolchain/worker.rb

Overview

Service class wraps a Tool instance when it is made part of an assembly.

TODO: Perhpas a better name would be ‘Link`, as in “chain link”?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, tool_class, options) ⇒ Worker

Create new wrapper.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/detroit/toolchain/worker.rb', line 41

def initialize(key, tool_class, options)
  @key = key

  ## set defaults
  @track    = nil
  @priority = 0
  @active   = true

  self.active   = options.delete('active')   if !options['active'].nil?
  self.track    = options.delete('track')    if options.key?('track')
  self.priority = options.delete('priority') if options.key?('priority')

  @tool = tool_class.new(options)
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



17
18
19
# File 'lib/detroit/toolchain/worker.rb', line 17

def active
  @active
end

#keyObject (readonly)

Returns the value of attribute key.



14
15
16
# File 'lib/detroit/toolchain/worker.rb', line 14

def key
  @key
end

#priorityObject

Returns the value of attribute priority.



16
17
18
# File 'lib/detroit/toolchain/worker.rb', line 16

def priority
  @priority
end

#toolObject (readonly)

Returns the value of attribute tool.



18
19
20
# File 'lib/detroit/toolchain/worker.rb', line 18

def tool
  @tool
end

#trackObject

Returns the value of attribute track.



15
16
17
# File 'lib/detroit/toolchain/worker.rb', line 15

def track
  @track
end

Instance Method Details

#inspectObject



76
77
78
# File 'lib/detroit/toolchain/worker.rb', line 76

def inspect
  "<#{self.class}:#{object_id} @key='#{key}'>"
end

#invoke(station, stop = nil) ⇒ Object

Run the service assembly station procedure.



71
72
73
# File 'lib/detroit/toolchain/worker.rb', line 71

def invoke(station, stop=nil)
  @tool.assemble(station.to_sym, :destination=>stop.to_sym)
end

#stop?(station, stop = nil) ⇒ Boolean, Symbol

Does the tool handle the given assembly station?

If ‘true` is returned than the station is handled by a method in the tool with the same name.

If a symbol is returned then the station is handled, but via the method named by the returned symbol.

Returns:

  • (Boolean, Symbol)


65
66
67
# File 'lib/detroit/toolchain/worker.rb', line 65

def stop?(station, stop=nil)
  @tool.assemble?(station.to_sym, :destination=>stop.to_sym)
end