Class Tap::Joins::Switch
In: lib/tap/joins/switch.rb
Parent: Join

A Switch join allows a block to determine which output from an array of outputs will receive the results of the input.

Methods

call   join   new  

Attributes

selector  [RW]  An object responding to call that return the index of the output to that receives the result.

Public Class methods

[Source]

    # File lib/tap/joins/switch.rb, line 21
21:       def initialize(config={}, app=Tap::App.current, &block)
22:         super(config, app)
23:         @selector = block
24:       end

Public Instance methods

[Source]

    # File lib/tap/joins/switch.rb, line 31
31:       def call(result)
32:         index = selector.call(result)
33:         
34:         unless index && output = outputs[index] 
35:           raise SwitchError, "no switch target at index: #{index}"
36:         end
37: 
38:         exe(output, result)
39:       end

[Source]

    # File lib/tap/joins/switch.rb, line 26
26:       def join(inputs, outputs, &block)
27:         @selector = block
28:         super(inputs, outputs)
29:       end

[Validate]