Class: Pipeline::Builder

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Builder

Returns a new instance of Builder.



3
4
5
6
7
8
9
10
11
# File 'lib/pipeline/builder.rb', line 3

def initialize(&block)
  if block_given?
    if block.arity == 1
      yield self
    else
      instance_eval(&block)
    end
  end
end

Instance Method Details

#call(env) ⇒ Object

Calls the operations in the stack

Parameters:

  • env (Object)
    • Optional initial input to the pipeline



24
25
26
27
# File 'lib/pipeline/builder.rb', line 24

def call(env)
  build_operation_chain(stack.dup).
    call(env.dup)
end

#inspect_stackObject

 Returns the internal stack array for reading as a frozen object



30
31
32
# File 'lib/pipeline/builder.rb', line 30

def inspect_stack
  stack.freeze
end

#use(operation, *args, &block) ⇒ Object

 Adds an operation to the internal stack

Parameters:

  • operation (Class)
    • The operation class

  • args (Array)
    • Arguments for the operation

  • block (Proc)
    • Optional block for the operation



17
18
19
20
# File 'lib/pipeline/builder.rb', line 17

def use(operation, *args, &block)
  stack << [operation, args, block]
  self
end