Class: ExecJS::ExternalRuntime
- Defined in:
- lib/execjs/external_runtime.rb
Defined Under Namespace
Classes: Context
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #deprecated? ⇒ Boolean
- #exec_runtime(filename) ⇒ Object
-
#initialize(options) ⇒ ExternalRuntime
constructor
A new instance of ExternalRuntime.
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() @name = [:name] @command = [:command] @runner_path = [:runner_path] @encoding = [:encoding] @deprecated = !![: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
#name ⇒ Object (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
88 89 90 91 |
# File 'lib/execjs/external_runtime.rb', line 88 def available? require 'json' binary ? true : false end |
#deprecated? ⇒ 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 |