Class: ExecJS::ExternalRuntime

Inherits:
Runtime
  • Object
show all
Defined in:
lib/execjs/external_runtime.rb

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Runtime

#compile, #context_class, #eval, #exec

Constructor Details

#initialize(options) ⇒ ExternalRuntime

Returns a new instance of ExternalRuntime.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/execjs/external_runtime.rb', line 71

def initialize(options)
  @name        = options[:name]
  @command     = options[:command]
  @runner_path = options[:runner_path]
  @encoding    = options[:encoding]
  @deprecated  = !!options[:deprecated]
  @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.



69
70
71
# File 'lib/execjs/external_runtime.rb', line 69

def name
  @name
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


88
89
90
91
# File 'lib/execjs/external_runtime.rb', line 88

def available?
  require 'json'
  binary ? true : false
end

#deprecated?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/execjs/external_runtime.rb', line 93

def deprecated?
  @deprecated
end

#exec_runtime(filename) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/execjs/external_runtime.rb', line 144

def exec_runtime(filename)
  io = IO.popen(binary.split(' ') << filename, @popen_options.merge({err: [:child, :out]}))
  output = io.read
  io.close

  if $?.success?
    output
  else
    raise RuntimeError, output
  end
end