Class: Tap::Joins::Switch
- Defined in:
- lib/tap/joins/switch.rb
Overview
A Switch join allows a block to determine which output from an array of outputs will receive the results of the input.
– Note that switch is NOT identified as a join that can be created from the command line. Switch inherently requires a block to select which output receives the input, and so cannot be loaded from data alone.
Switch facilitates in-code switch joins.
Defined Under Namespace
Classes: SwitchError
Instance Attribute Summary collapse
-
#selector ⇒ Object
An object responding to call that return the index of the output to that receives the result.
Attributes inherited from Tap::Join
Attributes inherited from App::Api
Instance Method Summary collapse
- #call(result) ⇒ Object
-
#initialize(config = {}, app = Tap::App.instance, &block) ⇒ Switch
constructor
A new instance of Switch.
- #join(inputs, outputs, &block) ⇒ Object
Methods inherited from Tap::Join
#associations, build, intern, parse!, #to_spec
Methods inherited from App::Api
#associations, build, help, inherited, parse, parse!, parser, #to_spec
Methods included from Signals
Methods included from Signals::ModuleMethods
Constructor Details
#initialize(config = {}, app = Tap::App.instance, &block) ⇒ Switch
Returns a new instance of Switch.
19 20 21 22 |
# File 'lib/tap/joins/switch.rb', line 19 def initialize(config={}, app=Tap::App.instance, &block) super(config, app) @selector = block end |
Instance Attribute Details
#selector ⇒ Object
An object responding to call that return the index of the output to that receives the result.
17 18 19 |
# File 'lib/tap/joins/switch.rb', line 17 def selector @selector end |
Instance Method Details
#call(result) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/tap/joins/switch.rb', line 29 def call(result) index = selector.call(result) unless index && output = outputs[index] raise SwitchError, "no switch target at index: #{index}" end dispatch(output, result) end |
#join(inputs, outputs, &block) ⇒ Object
24 25 26 27 |
# File 'lib/tap/joins/switch.rb', line 24 def join(inputs, outputs, &block) @selector = block super(inputs, outputs) end |