Module: ProxyPacRb::Runtimes

Defined in:
lib/proxy_pac_rb/runtimes.rb

Overview

JavaScript Runtimes

Constant Summary collapse

RubyRacer =
RubyRacerRuntime.new
RubyRhino =
RubyRhinoRuntime.new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.autodetectObject



9
10
11
12
13
# File 'lib/proxy_pac_rb/runtimes.rb', line 9

def autodetect
  from_environment || best_available ||
    raise(RuntimeUnavailableError, 'Could not find a JavaScript runtime. ' \
          'See https://github.com/sstephenson/execjs for a list of available runtimes.')
end

.best_availableObject



15
16
17
# File 'lib/proxy_pac_rb/runtimes.rb', line 15

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

.from_environmentObject



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

def from_environment
  return nil unless ENV['JS_RUNTIME']

  runtime = const_get(ENV['JS_RUNTIME'])

  raise RuntimeUnavailableError, "#{ENV['JS_RUNTIME']} runtime is not defined" unless runtime
  raise RuntimeUnavailableError, "#{runtime.name} runtime is not available on this system" unless runtime.available?

  runtime
end

.namesObject



30
31
32
# File 'lib/proxy_pac_rb/runtimes.rb', line 30

def names
  @names ||= constants.reduce({}) { |acc, elem| acc.merge(const_get(elem) => elem) }.values
end

.runtimesObject



34
35
36
37
38
39
# File 'lib/proxy_pac_rb/runtimes.rb', line 34

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

Instance Method Details

#runtimesObject



42
43
44
# File 'lib/proxy_pac_rb/runtimes.rb', line 42

def runtimes
  Runtimes.runtimes
end