Class: Pyper::Pipeline
- Inherits:
-
Object
- Object
- Pyper::Pipeline
- Defined in:
- lib/pyper/pipeline.rb
Instance Attribute Summary collapse
-
#pipes ⇒ Object
readonly
Returns the value of attribute pipes.
Class Method Summary collapse
-
.create(&block) ⇒ Pyper::Pipeline
Provides an interface for creating a pipeline.
Instance Method Summary collapse
- #<<(pipe) ⇒ Object (also: #add)
-
#initialize(pipes = []) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #method_missing(sym, *args, &block) ⇒ Object
-
#push(input) ⇒ PipeStatus
Insert something into the pipeline to be processed.
- #respond_to_missing?(sym, include_all = false) ⇒ Boolean
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
#pipes ⇒ Object (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.
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
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
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
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 |