Sha256: 30440eb9e27d177974af0eea9915f60f9eadc743f31ee5ca7c1f1882ab5d51e9

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module ProxyPacRb
  # JavaScript Runtimes
  module Runtimes
    RubyRacer = RubyRacerRuntime.new
    RubyRhino = RubyRhinoRuntime.new

    class << self
      def autodetect
        from_environment || best_available ||
          fail(Exceptions::RuntimeUnavailable, 'Could not find a JavaScript runtime. ' \
                'See https://github.com/sstephenson/execjs for a list of available runtimes.')
      end

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

      def from_environment
        return nil unless ENV['JS_RUNTIME']

        runtime = const_get(ENV['JS_RUNTIME'])

        fail Exceptions::RuntimeUnavailable, "#{ENV['JS_RUNTIME']} runtime is not defined" unless runtime
        fail Exceptions::RuntimeUnavailable, "#{runtime.name} runtime is not available on this system" unless runtime.available?

        runtime
      end

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

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

    def runtimes
      Runtimes.runtimes
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proxy_pac_rb-0.3.8 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.3.7 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.3.6 lib/proxy_pac_rb/runtimes.rb