Class: Traceur::Node::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/traceur/node/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
# File 'lib/traceur/node/runner.rb', line 6

def initialize(opts = {})
  @binary = opts.fetch(:binary)
  @modules_path = opts.fetch(:modules_path)
  @env = opts.fetch(:env)
end

Instance Method Details

#run(opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/traceur/node/runner.rb', line 12

def run(opts = {})
  input = opts.fetch(:input) { "" }
  arguments = opts.fetch(:arguments) { [] }
  on_error = opts.fetch(:on_error) { ->(r) {} }

  Open3.popen3(env, binary, *arguments) do |stdin, stdout, stderr, wait_thr|
    stdin.print input
    stdin.close

    CommandResult.new(
      stdout: stdout.read,
      stderr: stderr.read,
      status: wait_thr.value
    ).on_error(&on_error)
  end
end