Class: NodeRunner::Executor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Executor

Returns a new instance of Executor.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/node-runner.rb', line 86

def initialize(options = {})
  @command      = options[:command] || ['node']
  @modules_path = options[:modules_path] || File.join(Dir.pwd, "node_modules")
  @runner_path  = options[:runner_path] || File.join(File.expand_path(__dir__), '/node_runner.js')
  @encoding     = options[:encoding] || "UTF-8"
  @binary       = nil

  @popen_options = {}
  @popen_options[:external_encoding] = @encoding if @encoding
  @popen_options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'

  if @runner_path
    instance_eval generate_compile_method(@runner_path)
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



84
85
86
# File 'lib/node-runner.rb', line 84

def name
  @name
end

Instance Method Details

#exec(filename) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/node-runner.rb', line 102

def exec(filename)
  ENV["NODE_PATH"] = @modules_path
  stdout, stderr, status = Open3.capture3("#{binary} #{filename}")
  if status.success?
    stdout
  else
    raise exec_runtime_error(stderr)
  end
end