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.

[View source]

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

def initialize(options = {})
  @command     = options[:command] || ['node']
  @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

[View source]

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

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