Module: Pipetree::Flow::Operators

Included in:
Pipetree::Flow
Defined in:
lib/pipetree/flow.rb

Instance Method Summary collapse

Instance Method Details

#%(proc, options = {}) ⇒ Object



29
30
31
32
# File 'lib/pipetree/flow.rb', line 29

def %(proc, options={})
  # no condition is needed, and we want to stay on the same track, too.
  _insert Stay.new(proc), options, proc, "%"
end

#&(proc, options = {}) ⇒ Object

OnRight-> ? Right, input : Left, input



15
16
17
# File 'lib/pipetree/flow.rb', line 15

def &(proc, options={})
  _insert On.new(Right, And.new(proc)), options, proc, "&"
end

#<(proc, options = {}) ⇒ Object

Optimize the most common steps with Stay/And objects that are faster than procs.



10
11
12
# File 'lib/pipetree/flow.rb', line 10

def <(proc, options={})
  _insert On.new(Left, Stay.new(proc)), options, proc, "<"
end

#>(proc, options = {}) ⇒ Object

TODO: test me.



20
21
22
# File 'lib/pipetree/flow.rb', line 20

def >(proc, options={})
  _insert On.new(Right, Stay.new(proc)), options, proc, ">"
end

#>>(proc, options = {}) ⇒ Object



24
25
26
27
# File 'lib/pipetree/flow.rb', line 24

def >>(proc, options={})
  _insert On.new(Right,
    ->(last, input, options) { [Right, proc.(input, options)] } ), options, proc, ">>"
end

#_insert(step, options, original_proc, operator) ⇒ Object

:private: proc is the original step proc, e.g. Validate.



36
37
38
39
40
41
42
43
# File 'lib/pipetree/flow.rb', line 36

def _insert(step, options, original_proc, operator)
  options = { append: true }.merge(options)

  insert!(step, options).tap do
    @step2proc ||= StepMap.new
    @step2proc[step] = options[:name], original_proc, operator
  end
end

#index(proc) ⇒ Object

:private:



46
47
48
# File 'lib/pipetree/flow.rb', line 46

def index(proc) # @step2proc: { <On @proc> => {proc: @proc, name: "trb.validate", operator: "&"} }
  on = @step2proc.find_proc(proc) and return super(on)
end