class Hasta::ExecutionContext::Subprocess

A Subprocess

Attributes

env[R]
ruby_files[R]
source_file[R]
stderr[R]
stdin[R]
stdout[R]

Public Class Methods

new(ruby_files, env) click to toggle source
# File lib/hasta/execution_context.rb, line 14
def initialize(ruby_files, env)
  @ruby_files = ruby_files
  @env = env
end

Public Instance Methods

start(source_file) { |self| ... } click to toggle source
# File lib/hasta/execution_context.rb, line 19
def start(source_file)
  Open3.popen3(*cmd_line(source_file)) do |stdin, stdout, stderr, wait_thr|
    @stdin, @stdout, @stderr, @wait_thr = stdin, stdout, stderr, wait_thr

    yield self

    if (exit_code = wait_thr.value.exitstatus) != 0
      raise ExecutionError, "#{source_file} exited with non-zero status: #{exit_code}"
    end
  end
end

Private Instance Methods

cmd_line(source_file) click to toggle source
# File lib/hasta/execution_context.rb, line 35
def cmd_line(source_file)
  [env, ruby_exe_path] + load_path + [source_file]
end
load_path() click to toggle source
# File lib/hasta/execution_context.rb, line 43
def load_path
  ruby_files.
    map { |file| File.expand_path(File.dirname(file)) }.
    uniq.
    map { |path| ['-I', path] }.
    flatten
end
ruby_exe_path() click to toggle source
# File lib/hasta/execution_context.rb, line 39
def ruby_exe_path
  File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
end