Module: PAC::Runtimes

Defined in:
lib/pac/runtimes.rb,
lib/pac/runtimes/johnson.rb,
lib/pac/runtimes/mustang.rb,
lib/pac/runtimes/rubyracer.rb,
lib/pac/runtimes/rubyrhino.rb

Defined Under Namespace

Classes: JohnsonRuntime, MustangRuntime, RubyRacerRuntime, RubyRhinoRuntime

Constant Summary collapse

RubyRacer =
RubyRacerRuntime.new
RubyRhino =
RubyRhinoRuntime.new
Johnson =
JohnsonRuntime.new
Mustang =
MustangRuntime.new

Class Method Summary collapse

Class Method Details

.autodetectObject



14
15
16
# File 'lib/pac/runtimes.rb', line 14

def autodetect
  from_environment || best_available || raise(RuntimeUnavailable, "Could not find a JavaScript runtime. See https://github.com/samuelkadolph/ruby-pac for a list of runtimes.")
end

.best_availableObject



32
33
34
# File 'lib/pac/runtimes.rb', line 32

def best_available
  runtimes.find(&:available?)
end

.from_environmentObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pac/runtimes.rb', line 18

def from_environment
  if name = ENV["JS_RUNTIME"]
    if runtime = const_get(name)
      if runtime.available?
        runtime if runtime.available?
      else
        raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system"
      end
    elsif !name.empty?
      raise RuntimeUnavailable, "#{name} runtime is not defined"
    end
  end
end

.runtimesObject



36
37
38
# File 'lib/pac/runtimes.rb', line 36

def runtimes
  @runtimes ||= [RubyRacer, RubyRhino, Johnson, Mustang]
end