Class: TypedOperation::Pipeline::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/typed_operation/pipeline/builder.rb

Overview

Builder class for the Pipeline DSL.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

: () -> void



15
16
17
18
# File 'lib/typed_operation/pipeline/builder.rb', line 15

def initialize
  @steps = []
  @failure_handler = nil
end

Instance Attribute Details

#failure_handlerObject (readonly)

: (^(untyped, Symbol) -> untyped)?



12
13
14
# File 'lib/typed_operation/pipeline/builder.rb', line 12

def failure_handler
  @failure_handler
end

#stepsObject (readonly)

Returns the value of attribute steps.



11
12
13
# File 'lib/typed_operation/pipeline/builder.rb', line 11

def steps
  @steps
end

Instance Method Details

#fallback(operation = nil, &block) ⇒ Object Also known as: or_else

Define a fallback for error recovery. : (?untyped) ?{ (untyped) -> untyped } -> void



55
56
57
58
59
60
61
62
# File 'lib/typed_operation/pipeline/builder.rb', line 55

def fallback(operation = nil, &block)
  @steps << {
    type: :fallback,
    name: operation ? derive_name(operation) : :fallback,
    operation: operation || block,
    condition: nil
  }
end

#on_failure(&block) ⇒ Object

Define a failure handler for the pipeline. : () { (untyped, Symbol) -> untyped } -> void



67
68
69
# File 'lib/typed_operation/pipeline/builder.rb', line 67

def on_failure(&block)
  @failure_handler = block
end

#step(name_or_operation, operation = nil, if: nil) ⇒ Object

Define a step in the pipeline. : (Symbol | untyped, ?untyped, ?if: (^(untyped) -> boolish)?) -> void



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/typed_operation/pipeline/builder.rb', line 22

def step(name_or_operation, operation = nil, if: nil)
  condition = binding.local_variable_get(:if)

  @steps << if operation
    {
      type: :step,
      name: name_or_operation,
      operation: operation,
      condition: condition
    }
  else
    {
      type: :step,
      name: derive_name(name_or_operation),
      operation: name_or_operation,
      condition: condition
    }
  end
end

#transform(&block) ⇒ Object

Define a transform step that maps the success value. : () { (untyped) -> untyped } -> void



44
45
46
47
48
49
50
51
# File 'lib/typed_operation/pipeline/builder.rb', line 44

def transform(&block)
  @steps << {
    type: :transform,
    name: :transform,
    operation: block,
    condition: nil
  }
end