class Coque::Pipeline
Attributes
commands[R]
Public Class Methods
new(commands = [])
click to toggle source
# File lib/coque/pipeline.rb, line 7 def initialize(commands = []) @commands = commands end
Public Instance Methods
clone()
click to toggle source
# File lib/coque/pipeline.rb, line 11 def clone self.class.new(commands) end
get_result()
click to toggle source
# File lib/coque/pipeline.rb, line 60 def get_result stdout = stitch results = commands.map(&:run) Result.new(results.last.pid, stdout) end
pipe(other)
click to toggle source
# File lib/coque/pipeline.rb, line 19 def pipe(other) case other when Pipeline Pipeline.new(commands + other.commands) when Cmd Pipeline.new(commands + [other.clone]) end end
stitch()
click to toggle source
# File lib/coque/pipeline.rb, line 32 def stitch # Set head in if commands.first.stdin.nil? start_r, start_w = IO.pipe start_w.close commands.first.stdin = start_r end # Connect intermediate in/outs commands.each_cons(2) do |left, right| read, write = IO.pipe left.stdout = write right.stdin = read end # Set tail out if self.stdout commands.last.stdout = stdout stdout elsif commands.last.stdout commands.last.stdout else next_r, next_w = IO.pipe commands.last.stdout = next_w next_r end end
to_s()
click to toggle source
# File lib/coque/pipeline.rb, line 15 def to_s "<Pipeline #{commands.join(" | ")} >" end
|(other)
click to toggle source
# File lib/coque/pipeline.rb, line 28 def |(other) pipe(other) end