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 = {} [: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.
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
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/execjs/external_runtime.rb', line 145 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 |