Class: Piperator::Builder

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

Overview

Builder is used to provide DSL-based Pipeline building. Using Builder, Pipelines can be built without pipe chaining, which might be easier if some steps need to be included only on specific conditions.

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(saved_binding, pipeline = Pipeline.new) ⇒ Builder

Returns a new instance of Builder.



27
28
29
30
# File 'lib/piperator/builder.rb', line 27

def initialize(saved_binding, pipeline = Pipeline.new)
  @pipeline = pipeline
  @saved_binding = saved_binding
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object (private)



41
42
43
44
45
46
47
# File 'lib/piperator/builder.rb', line 41

def method_missing(method_name, *arguments, &block)
  if @saved_binding.receiver.respond_to?(method_name, true)
    @saved_binding.receiver.send(method_name, *arguments, &block)
  else
    super
  end
end

Class Method Details

.dsl_method(method_name) ⇒ Object

Expose a chained method in Pipeline in DSL

Parameters:

  • method_name

    Name of method in Pipeline

See Also:



18
19
20
21
22
# File 'lib/piperator/builder.rb', line 18

def self.dsl_method(method_name)
  define_method(method_name) do |*arguments|
    @pipeline = @pipeline.send(method_name, *arguments)
  end
end

Instance Method Details

#pipeObject

Call Pipeline#pipe given arguments and use the return value as builder state.

See Also:



24
# File 'lib/piperator/builder.rb', line 24

dsl_method :pipe

#to_pipelinePipeline

Return build pipeline

Returns:



35
36
37
# File 'lib/piperator/builder.rb', line 35

def to_pipeline
  @pipeline
end

#wrapObject

Call Pipeline#wrap given arguments and use the return value as builder state.

See Also:



25
# File 'lib/piperator/builder.rb', line 25

dsl_method :wrap