Class: PiecePipe::Pipeline
- Inherits:
-
Object
- Object
- PiecePipe::Pipeline
- Defined in:
- lib/piece_pipe/pipeline.rb
Instance Method Summary collapse
- #assembly_step(step) ⇒ Object
- #collect(key) ⇒ Object
- #debug(opts) ⇒ Object
-
#group_by(*keys) ⇒ Object
like rails group by, takes the entire row and keys it based on the fields.
-
#initialize ⇒ Pipeline
constructor
A new instance of Pipeline.
- #input(item) ⇒ Object
- #result ⇒ Object
- #source(source) ⇒ Object
- #step(step) ⇒ Object
- #tap(&block) ⇒ Object
- #to_a ⇒ Object
- #to_enum ⇒ Object (also: #smoke)
Constructor Details
#initialize ⇒ Pipeline
Returns a new instance of Pipeline.
3 4 5 |
# File 'lib/piece_pipe/pipeline.rb', line 3 def initialize @latest_source = nil end |
Instance Method Details
#assembly_step(step) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/piece_pipe/pipeline.rb', line 28 def assembly_step(step) case step when Class step = step.new # If the arg is a Class, instantiate it when Method step = MethodAssemblyStep.new(step) end add_step step end |
#collect(key) ⇒ Object
59 60 61 |
# File 'lib/piece_pipe/pipeline.rb', line 59 def collect(key) step(Collector.new(key)) end |
#debug(opts) ⇒ Object
55 56 57 |
# File 'lib/piece_pipe/pipeline.rb', line 55 def debug(opts) step(DebugStep.new(opts)) end |
#group_by(*keys) ⇒ Object
like rails group by, takes the entire row and keys it based on the fields
40 41 42 |
# File 'lib/piece_pipe/pipeline.rb', line 40 def group_by(*keys) add_step(GroupByStep.new(*keys)) end |
#input(item) ⇒ Object
13 14 15 16 |
# File 'lib/piece_pipe/pipeline.rb', line 13 def input(item) source [item] self end |
#result ⇒ Object
63 64 65 |
# File 'lib/piece_pipe/pipeline.rb', line 63 def result to_enum.first end |
#source(source) ⇒ Object
7 8 9 10 11 |
# File 'lib/piece_pipe/pipeline.rb', line 7 def source(source) raise "Source already set to #{@latest_source.inspect}" unless @latest_source.nil? @latest_source = source self end |
#step(step) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/piece_pipe/pipeline.rb', line 18 def step(step) case step when Class step = step.new # If the arg is a Class, instantiate it when Method step = MethodStep.new(step) end add_step step end |
#tap(&block) ⇒ Object
51 52 53 |
# File 'lib/piece_pipe/pipeline.rb', line 51 def tap(&block) step(TapStep.new(&block)) end |
#to_a ⇒ Object
72 73 74 |
# File 'lib/piece_pipe/pipeline.rb', line 72 def to_a to_enum.to_a end |
#to_enum ⇒ Object Also known as: smoke
67 68 69 |
# File 'lib/piece_pipe/pipeline.rb', line 67 def to_enum @latest_source.to_enum end |