Class: Tap::Join

Inherits:
App::Api show all
Defined in:
lib/tap/join.rb

Overview

:startdoc::join unsyncrhonized multi-way join

Join defines an unsynchronized, multi-way join where n inputs send their results to m outputs. Flags can augment how the results are passed, in particular for array results.

Instance Attribute Summary collapse

Attributes inherited from App::Api

#app

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from App::Api

help, inherited, #inspect, parse, parse!, parser

Methods included from Signals

#sig, #signal, #signal?, #signals

Methods included from Signals::ModuleMethods

included

Constructor Details

#initialize(config = {}, app = Tap::App.current) ⇒ Join

Initializes a new join with the specified configuration.



96
97
98
99
100
# File 'lib/tap/join.rb', line 96

def initialize(config={}, app=Tap::App.current)
  @inputs = nil
  @outputs = nil
  super
end

Instance Attribute Details

#inputsObject (readonly)

An array of input tasks, or nil if the join has not been set.



90
91
92
# File 'lib/tap/join.rb', line 90

def inputs
  @inputs
end

#outputsObject (readonly)

An array of output tasks, or nil if the join has not been set.



93
94
95
# File 'lib/tap/join.rb', line 93

def outputs
  @outputs
end

Class Method Details

.build(spec = {}, app = Tap::App.current) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tap/join.rb', line 12

def build(spec={}, app=Tap::App.current)
  inputs = resolve(spec['inputs']) do |var|
    app.get(var) or raise "missing join input: #{var}"
  end
  
  outputs = resolve(spec['outputs']) do |var|
    app.get(var) or raise "missing join output: #{var}"
  end
  
  new(spec['config'] || {}, app).join(inputs, outputs)
end

Instance Method Details

#associationsObject



132
133
134
# File 'lib/tap/join.rb', line 132

def associations
  [inputs + outputs]
end

#call(result) ⇒ Object

Executes the join logic for self, which by default passes the result to each output.



126
127
128
129
130
# File 'lib/tap/join.rb', line 126

def call(result)
  outputs.each do |output|
    exe(output, result)
  end
end

#join(inputs, outputs) ⇒ Object

Sets self as a join between the inputs and outputs.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/tap/join.rb', line 103

def join(inputs, outputs)
  @inputs.each do |input|
    input.joins.delete(self)
  end if @inputs
  
  inputs.each do |input|
    unless input.respond_to?(:joins)
      raise "input does not support joins: #{input.inspect}"
    end
  end
  
  @inputs = inputs
  
  inputs.each do |input|
    input.joins << self
  end if inputs
  
  @outputs = outputs
  self
end

#to_specObject



136
137
138
139
140
141
# File 'lib/tap/join.rb', line 136

def to_spec
  spec = super
  spec['inputs'] = inputs.collect {|task| app.var(task) }
  spec['outputs'] = outputs.collect {|task| app.var(task) }
  spec
end