Class: Philiprehberger::Pipe::Step

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callable:, name: nil, type: :transform, guard_if: nil, guard_unless: nil) ⇒ Step

Returns a new instance of Step.



8
9
10
11
12
13
14
# File 'lib/philiprehberger/pipe/step.rb', line 8

def initialize(callable:, name: nil, type: :transform, guard_if: nil, guard_unless: nil)
  @callable = callable
  @name = name
  @type = type
  @guard_if = guard_if
  @guard_unless = guard_unless
end

Instance Attribute Details

#callableObject (readonly)

Returns the value of attribute callable.



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

def callable
  @callable
end

#guard_ifObject (readonly)

Returns the value of attribute guard_if.



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

def guard_if
  @guard_if
end

#guard_unlessObject (readonly)

Returns the value of attribute guard_unless.



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

def guard_unless
  @guard_unless
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#execute(value) ⇒ Object



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

def execute(value)
  return value if skipped?(value)

  result = callable.call(value)
  type == :tee ? value : result
rescue PipeError, Halted
  raise
rescue StandardError => e
  raise PipeError.new(e.message, step_name: name, original_error: e)
end