diff --git a/lib/execjs.rb b/lib/execjs.rb index 27d1c18..2fa145e 100644 --- a/lib/execjs.rb +++ b/lib/execjs.rb @@ -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) diff --git a/lib/execjs/runtime.rb b/lib/execjs/external_runtime.rb similarity index 98% rename from lib/execjs/runtime.rb rename to lib/execjs/external_runtime.rb index de0b3f2..50515ac 100644 --- a/lib/execjs/runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -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}` diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb index 1d56913..dae435c 100644 --- a/lib/execjs/runtimes.rb +++ b/lib/execjs/runtimes.rb @@ -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 diff --git a/test/test_execjs.rb b/test/test_execjs.rb index 3ec4610..dfd1ad0 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -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