# File lib/execjs/external_runtime.rb, line 91 def initialize(options) @name = options[:name] @command = options[:command] @runner_path = options[:runner_path] @test_args = options[:test_args] @test_match = options[:test_match] @encoding = options[:encoding] @deprecated = !!options[:deprecated] @binary = nil end
# File lib/execjs/external_runtime.rb, line 102 def available? require "execjs/json" binary ? true : false end
# File lib/execjs/external_runtime.rb, line 107 def deprecated? @deprecated end
# File lib/execjs/external_runtime.rb, line 137 def exec_runtime(filename) output = sh("#{shell_escape(*(binary.split(' ') << filename))} 2>&1") if $?.success? output else raise RuntimeError, output end end
# File lib/execjs/external_runtime.rb, line 146 def locate_binary if binary = which(@command) if @test_args output = %x#{shell_escape(binary, @test_args)} 2>&1` binary if output.match(@test_match) else binary end end end
# File lib/execjs/external_runtime.rb, line 133 def runner_source @runner_source ||= IO.read(@runner_path) end
# File lib/execjs/external_runtime.rb, line 169 def sh(command) output, options = nil, {} options[:external_encoding] = @encoding if @encoding options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8' IO.popen(command, options) { |f| output = f.read } output end
# File lib/execjs/external_runtime.rb, line 192 def shell_escape(*args) # see http://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection123121120120 args.map { |arg| arg = %Q("#{arg.gsub('"','""')}") if arg.match(%r[&|()<>^ "]/) arg }.join(" ") end
# File lib/execjs/external_runtime.rb, line 157 def which(command) Array(command).find do |name| name, args = name.split(%r\s+/, 2) path = locate_executable(name) next unless path args ? "#{path} #{args}" : path end end