Class: Philiprehberger::Pipe::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/pipe/pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePipeline

Returns a new instance of Pipeline.



8
9
10
# File 'lib/philiprehberger/pipe/pipeline.rb', line 8

def initialize
  @steps = []
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



6
7
8
# File 'lib/philiprehberger/pipe/pipeline.rb', line 6

def steps
  @steps
end

Instance Method Details

#add_step(step) ⇒ Object



12
13
14
# File 'lib/philiprehberger/pipe/pipeline.rb', line 12

def add_step(step)
  @steps << step
end

#execute(initial_value, error_handler: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/philiprehberger/pipe/pipeline.rb', line 16

def execute(initial_value, error_handler: nil)
  @steps.reduce(initial_value) do |value, step|
    step.execute(value)
  end
rescue Halted => e
  e.value
rescue StandardError => e
  raise unless error_handler

  error_handler.call(e)
end