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.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/execjs/external_runtime.rb', line 74 def initialize() @name = [:name] @command = [:command] @runner_path = [:runner_path] @encoding = [:encoding] @deprecated = !![:deprecated] @binary = nil = {} [:external_encoding] = @encoding if @encoding [: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.
72 73 74 |
# File 'lib/execjs/external_runtime.rb', line 72 def name @name end |
Instance Method Details
#available? ⇒ Boolean
91 92 93 94 |
# File 'lib/execjs/external_runtime.rb', line 91 def available? require 'json' binary ? true : false end |
#deprecated? ⇒ Boolean
96 97 98 |
# File 'lib/execjs/external_runtime.rb', line 96 def deprecated? @deprecated end |
#exec_runtime(filename) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/execjs/external_runtime.rb', line 148 def exec_runtime(filename) path = Dir::Tmpname.create(['execjs', 'json']) {} begin command = binary.split(" ") << filename `#{shell_escape(*command)} 2>&1 > #{path}` output = File.open(path, 'rb', ) { |f| f.read } ensure File.unlink(path) if path end if $?.success? output else raise RuntimeError, output end end |