Class: Jrf::Pipeline
- Inherits:
-
Object
- Object
- Jrf::Pipeline
- Defined in:
- lib/jrf/pipeline.rb
Instance Method Summary collapse
-
#call(input) {|value| ... } ⇒ Array?
Run the pipeline on an enumerable of input values.
-
#initialize(*blocks) ⇒ Pipeline
constructor
A new instance of Pipeline.
Constructor Details
#initialize(*blocks) ⇒ Pipeline
Returns a new instance of Pipeline.
9 10 11 12 13 14 |
# File 'lib/jrf/pipeline.rb', line 9 def initialize(*blocks) raise ArgumentError, "at least one stage block is required" if blocks.empty? @ctx = RowContext.new @stages = blocks.map { |block| Stage.new(@ctx, block, src: nil) } end |
Instance Method Details
#call(input) {|value| ... } ⇒ Array?
Run the pipeline on an enumerable of input values.
Without a block, returns an Array of output values. With a block, streams each output value to the block.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jrf/pipeline.rb', line 24 def call(input, &on_output) if on_output.nil? results = [] on_output = proc { |value| results << value } end begin input.each { |value| process_value(value, @stages, &on_output) } ensure flush_reducers(@stages, &on_output) end results unless results.nil? end |