mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Runtime -> ExternalRuntime
This commit is contained in:
parent
39b51331ce
commit
c5e22c4716
4 changed files with 13 additions and 12 deletions
|
@ -3,8 +3,8 @@ module ExecJS
|
|||
class RuntimeError < Error; end
|
||||
class ProgramError < Error; end
|
||||
|
||||
autoload :Runtime, "execjs/runtime"
|
||||
autoload :Runtimes, "execjs/runtimes"
|
||||
autoload :ExternalRuntime, "execjs/external_runtime"
|
||||
autoload :Runtimes, "execjs/runtimes"
|
||||
|
||||
def self.exec(source)
|
||||
runtime.exec(source)
|
||||
|
|
|
@ -2,24 +2,24 @@ require "json"
|
|||
require "tempfile"
|
||||
|
||||
module ExecJS
|
||||
class Runtime
|
||||
class ExternalRuntime
|
||||
def initialize(options)
|
||||
@command = options[:command]
|
||||
@runner_path = options[:runner_path]
|
||||
end
|
||||
|
||||
def exec(source)
|
||||
compile_to_tempfile(source) do |file|
|
||||
extract_result(exec_runtime(file.path))
|
||||
end
|
||||
end
|
||||
|
||||
def eval(source)
|
||||
if /\S/ =~ source
|
||||
exec("return eval(#{"(#{source})".to_json})")
|
||||
end
|
||||
end
|
||||
|
||||
def exec(source)
|
||||
compile_to_tempfile(source) do |file|
|
||||
extract_result(exec_runtime(file.path))
|
||||
end
|
||||
end
|
||||
|
||||
def available?
|
||||
command = @command.split(/\s+/).first
|
||||
`which #{command}`
|
|
@ -9,7 +9,8 @@ module ExecJS
|
|||
end
|
||||
|
||||
def self.define_runtime(name, options)
|
||||
runtimes.push runtime = Runtime.new(options)
|
||||
klass = options[:as] || ExternalRuntime
|
||||
runtimes.push runtime = klass.new(options)
|
||||
const_set(name, runtime)
|
||||
end
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ class TestExecJS < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_runtime_available
|
||||
runtime = ExecJS::Runtime.new(:command => "nonexistent")
|
||||
runtime = ExecJS::ExternalRuntime.new(:command => "nonexistent")
|
||||
assert_equal false, runtime.available?
|
||||
|
||||
runtime = ExecJS::Runtime.new(:command => "ruby")
|
||||
runtime = ExecJS::ExternalRuntime.new(:command => "ruby")
|
||||
assert_equal true, runtime.available?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue