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
- .autodetect ⇒ Object
- .best_available ⇒ Object
- .from_environment ⇒ Object
- .names ⇒ Object
- .runtimes ⇒ Object
Instance Method Summary collapse
Class Method Details
.autodetect ⇒ Object
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_available ⇒ Object
15 16 17 |
# File 'lib/proxy_pac_rb/runtimes.rb', line 15 def best_available runtimes.reject(&:deprecated?).find(&:available?) end |
.from_environment ⇒ Object
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 |
.names ⇒ Object
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 |
.runtimes ⇒ Object
34 35 36 37 38 39 |
# File 'lib/proxy_pac_rb/runtimes.rb', line 34 def runtimes @runtimes ||= [ RubyRacer, RubyRhino ] end |
Instance Method Details
#runtimes ⇒ Object
42 43 44 |
# File 'lib/proxy_pac_rb/runtimes.rb', line 42 def runtimes Runtimes.runtimes end |