Class: Rbsh::Pipeline

Inherits:
BasicObject
Defined in:
lib/rbsh/pipeline.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args, &block) ⇒ Pipeline

Returns a new instance of Pipeline.



6
7
8
# File 'lib/rbsh/pipeline.rb', line 6

def initialize(name, *args, &block)
  _push(name, *args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

def method_missing(name, *args, &block)
  _push(name, *args)
  self
end

Instance Attribute Details

#_queue=(value) ⇒ Object

Sets the attribute _queue

Parameters:

  • value

    the value to set the attribute _queue to.



4
5
6
# File 'lib/rbsh/pipeline.rb', line 4

def _queue=(value)
  @_queue = value
end

Instance Method Details

#run!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rbsh/pipeline.rb', line 10

def run!
  commands = _queue.map do |c|
    [ c[:command], *c[:args] ].compact.map(&:to_s)
  end

  result = Result.new
  ::Open3.pipeline_rw(*commands) do |stdin, stdout, wait_threads|
    stdin.close
    lines = stdout.readlines
    lines = ["\n"] if lines.size == 0
    result.set(lines)
  end
  result
end