Class: Pyper::Pipeline

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipes = []) ⇒ Pipeline

Returns a new instance of Pipeline.



27
28
29
# File 'lib/pyper/pipeline.rb', line 27

def initialize(pipes = [])
  @pipes = pipes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



55
56
57
# File 'lib/pyper/pipeline.rb', line 55

def method_missing(sym, *args, &block)
  @original_self ? @original_self.send(sym, *args, &block) : super
end

Instance Attribute Details

#pipesObject (readonly)

Returns the value of attribute pipes.



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

def pipes
  @pipes
end

Class Method Details

.create(&block) ⇒ Pyper::Pipeline

Provides an interface for creating a pipeline. The provided block will be called in the context of a newly-created pipeline, to which pipes can be added using #add.

Returns:



13
14
15
16
17
18
19
20
21
22
# File 'lib/pyper/pipeline.rb', line 13

def create(&block)
  new.tap do |pipeline|
    if block_given?
      original_self = eval('self', block.binding)
      pipeline.instance_variable_set(:@original_self, original_self)
      pipeline.instance_eval(&block)
      pipeline.remove_instance_variable(:@original_self)
    end
  end
end

Instance Method Details

#<<(pipe) ⇒ Object Also known as: add

Parameters:

  • pipe (#pipe|#call)

    A pipe to append to the pipeline



32
33
34
35
# File 'lib/pyper/pipeline.rb', line 32

def <<(pipe)
  pipes << pipe
  self
end

#push(input) ⇒ PipeStatus

Insert something into the pipeline to be processed

Parameters:

  • input (Object)

    The original input data to enter the pipeline. This may be mutated by each pipe in the pipeline.

Returns:

  • (PipeStatus)

    the pipe status, containing both the value and a status hash.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pyper/pipeline.rb', line 42

def push(input)
  status = {}
  value = pipes.inject(input) do |attributes, p|
    if p.respond_to?(:call)
      p.call(attributes, status)
    else
      p.pipe(attributes, status)
    end
  end

  PipeStatus.new(value, status)
end

#respond_to_missing?(sym, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/pyper/pipeline.rb', line 59

def respond_to_missing?(sym, include_all = false)
  @original_self ? @original_self.respond_to?(sym, include_all) : super
end