Class: Hasta::ExecutionContext::Subprocess

Inherits:
Object
  • Object
show all
Defined in:
lib/hasta/execution_context.rb

Overview

A Subprocess

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby_files, env) ⇒ Subprocess

Returns a new instance of Subprocess.



14
15
16
17
# File 'lib/hasta/execution_context.rb', line 14

def initialize(ruby_files, env)
  @ruby_files = ruby_files
  @env = env
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



12
13
14
# File 'lib/hasta/execution_context.rb', line 12

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



12
13
14
# File 'lib/hasta/execution_context.rb', line 12

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



12
13
14
# File 'lib/hasta/execution_context.rb', line 12

def stdout
  @stdout
end

Instance Method Details

#start(source_file) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# 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