Sha256: baaa7dfe50da7809ccb6884e397eb3b312203344e0644b0a78fd992bda5d8285

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

module ProxyPacRb
  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
        if name = ENV["JS_RUNTIME"]
          if runtime = const_get(name)
            if runtime.available?
              runtime if runtime.available?
            else
              fail Exceptions::RuntimeUnavailable, "#{runtime.name} runtime is not available on this system"
            end
          elsif !name.empty?
            fail Exceptions::RuntimeUnavailable, "#{name} runtime is not defined"
          end
        end
      end

      def names
        @names ||= constants.inject({}) { |h, name| h.merge(const_get(name) => name) }.values
      end

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

    def runtimes
      Runtimes.runtimes
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
proxy_pac_rb-0.3.4 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.3.3 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.3.2 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.3.0 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.2.6 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.2.5 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.2.4 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.2.3 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.2.2 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.2.1 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.2.0 lib/proxy_pac_rb/runtimes.rb
proxy_pac_rb-0.0.3 lib/proxy_pac_rb/runtimes.rb