Parent

ExecJS::ExternalRuntime

Attributes

name[R]

Public Class Methods

new(options) click to toggle source
# 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

Public Instance Methods

available?() click to toggle source
# File lib/execjs/external_runtime.rb, line 102
def available?
  require "execjs/json"
  binary ? true : false
end
deprecated?() click to toggle source
# File lib/execjs/external_runtime.rb, line 107
def deprecated?
  @deprecated
end

Protected Instance Methods

exec_runtime(filename) click to toggle source
# 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
locate_binary() click to toggle source
# File lib/execjs/external_runtime.rb, line 146
def locate_binary
  if binary = which(@command)
    if @test_args
      output = `#{shell_escape(binary, @test_args)} 2>&1`
      binary if output.match(@test_match)
    else
      binary
    end
  end
end
runner_source() click to toggle source
# File lib/execjs/external_runtime.rb, line 133
def runner_source
  @runner_source ||= IO.read(@runner_path)
end
sh(command) click to toggle source
# 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
shell_escape(*args) click to toggle source
# 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 = %("#{arg.gsub('"','""')}") if arg.match(/[&|()<>^ "]/)
    arg
  }.join(" ")
end
which(command) click to toggle source
# File lib/execjs/external_runtime.rb, line 157
def which(command)
  Array(command).find do |name|
    name, args = name.split(/\s+/, 2)
    path = locate_executable(name)

    next unless path

    args ? "#{path} #{args}" : path
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.