Class: Sevgi::Function::Shell::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/sevgi/function/shell.rb

Overview

Adapted to popen3 from github.com/mina-deploy/mina

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



35
36
37
# File 'lib/sevgi/function/shell.rb', line 35

def initialize
  @coathooks = 0
end

Instance Method Details

#call(*args, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sevgi/function/shell.rb', line 39

def call(*args, &block)
  return Result.dummy if args.empty?

  outs, errs, status = Open3.popen3(*args) do |stdin, stdout, stderr, wait_thread|
    if block
      input = block.call
      stdin.write(block.call) if input
      stdin.close
    end

    block(stdout, stderr, wait_thread)
  end

  Result.new(args, outs, errs, status.exitstatus)
end