Class: PVC::Pipeline
- Inherits:
-
Object
- Object
- PVC::Pipeline
- Defined in:
- lib/pvc/pipeline.rb
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #input(input) ⇒ Object
- #lines_map(&block) ⇒ Object
- #lines_tap(&block) ⇒ Object
- #only_err ⇒ Object
- #run ⇒ Object
- #to(*args, &block) ⇒ Object
- #with_err ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ Pipeline
Returns a new instance of Pipeline.
16 17 18 19 20 21 |
# File 'lib/pvc/pipeline.rb', line 16 def initialize(*args, &block) @pieces = [] if args.length > 0 || block_given? self.to(*args, &block) end end |
Instance Method Details
#input(input) ⇒ Object
34 35 36 37 |
# File 'lib/pvc/pipeline.rb', line 34 def input(input) @pieces << InputPiece.new(input) self end |
#lines_map(&block) ⇒ Object
49 50 51 52 |
# File 'lib/pvc/pipeline.rb', line 49 def lines_map(&block) @pieces << LinesPiece.new(block, :mode => :map) self end |
#lines_tap(&block) ⇒ Object
54 55 56 57 |
# File 'lib/pvc/pipeline.rb', line 54 def lines_tap(&block) @pieces << LinesPiece.new(block, :mode => :tap) self end |
#only_err ⇒ Object
44 45 46 47 |
# File 'lib/pvc/pipeline.rb', line 44 def only_err @pieces << OnlyErrPiece.new self end |
#run ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pvc/pipeline.rb', line 59 def run runners = ([NullPiece.new] + @pieces + [ResultPiece.new]).map(&:runner) runners.zip(runners[1..-1]).reverse.each do |current, following| current.start(following) end runners.each do |current| current.finish end Result.new( :stdout => runners.last.stdout, :stderr => runners.last.stderr, :stdboth => runners.last.stdboth, :codes => runners.inject([]) { |codes, runner| codes << runner.code if runner.respond_to?(:code); codes }, :returns => runners.inject([]) { |returns, runner| returns << runner.return if runner.respond_to?(:return); returns } ) end |
#to(*args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pvc/pipeline.rb', line 23 def to(*args, &block) if block_given? @pieces << BlockPiece.new(&block) elsif args.length == 1 && args.first.respond_to?(:pieces, true) args.first.pieces.each { |piece| @pieces << piece } else @pieces << ProcessPiece.new(*args) end self end |
#with_err ⇒ Object
39 40 41 42 |
# File 'lib/pvc/pipeline.rb', line 39 def with_err @pieces << WithErrPiece.new self end |