Module: Pipetree::Flow::Operators

Extended by:
Uber::Delegates
Included in:
Pipetree::Flow
Defined in:
lib/pipetree/flow.rb

Overview

TODO: don’t inherit from Array, because we don’t want Array[].

Instance Method Summary collapse

Instance Method Details

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



36
37
38
39
# File 'lib/pipetree/flow.rb', line 36

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



22
23
24
# File 'lib/pipetree/flow.rb', line 22

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.



17
18
19
# File 'lib/pipetree/flow.rb', line 17

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

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

TODO: test me.



27
28
29
# File 'lib/pipetree/flow.rb', line 27

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

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



31
32
33
34
# File 'lib/pipetree/flow.rb', line 31

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.



43
44
45
46
47
48
49
50
51
# File 'lib/pipetree/flow.rb', line 43

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

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

  self
end

#index(proc) ⇒ Object

:private:



54
55
56
# File 'lib/pipetree/flow.rb', line 54

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