class Traceur::Node::Runner
Attributes
binary[R]
modules_path[R]
Public Class Methods
new(opts = {})
click to toggle source
# 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
Public Instance Methods
run(opts = {})
click to toggle source
# 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
Private Instance Methods
env()
click to toggle source
# File lib/traceur/node/runner.rb, line 31 def env @env.merge("NODE_PATH" => modules_path) do |_, old, new| "#{old}:#{new}" end end