Class: Tap::Support::Joins::Switch

Inherits:
Tap::Support::Join show all
Defined in:
lib/tap/support/joins/switch.rb

Overview

A Switch join allows a block to determine which target from set of targets will receive the results of the source.

Constant Summary

Constants inherited from Tap::Support::Join

Tap::Support::Join::FLAGS, Tap::Support::Join::SHORT_FLAGS

Instance Method Summary collapse

Methods inherited from Tap::Support::Join

#initialize, #inspect, join, #name, #options

Constructor Details

This class inherits a constructor from Tap::Support::Join

Instance Method Details

#join(source, targets) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tap/support/joins/switch.rb', line 8

def join(source, targets)
  complete(source) do |_result| 
    if index = yield(_result)        
      unless target = targets[index] 
        raise "no switch target for index: #{index}"
      end

      enq(target, _result)
    else
      source.app.aggregator.store(_result)
    end
  end
end