Sha256: a3e01c8fadd4197862508f0e7e13b9579d4a810ddc2efe5179b48bdb5e4d435d

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

require_relative '../puppet/http'
require 'singleton'

# Provides access to runtime implementations.
#
# @api private
class Puppet::Runtime
  include Singleton

  def initialize
    @runtime_services = {
      http: proc do
        klass = Puppet::Network::HttpPool.http_client_class
        if klass == Puppet::Network::HTTP::Connection
          Puppet::HTTP::Client.new
        else
          Puppet::HTTP::ExternalClient.new(klass)
        end
      end
    }
  end
  private :initialize

  # Get a runtime implementation.
  #
  # @param name [Symbol] the name of the implementation
  # @return [Object] the runtime implementation
  # @api private
  def [](name)
    service = @runtime_services[name]
    raise ArgumentError, "Unknown service #{name}" unless service

    if service.is_a?(Proc)
      @runtime_services[name] = service.call
    else
      service
    end
  end

  # Register a runtime implementation.
  #
  # @param name [Symbol] the name of the implementation
  # @param impl [Object] the runtime implementation
  # @api private
  def []=(name, impl)
    @runtime_services[name] = impl
  end

  # Clears all implementations. This is used for testing.
  #
  # @api private
  def clear
    initialize
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
puppet-7.10.0 lib/puppet/runtime.rb
puppet-7.10.0-x86-mingw32 lib/puppet/runtime.rb
puppet-7.10.0-x64-mingw32 lib/puppet/runtime.rb
puppet-7.10.0-universal-darwin lib/puppet/runtime.rb
puppet-7.9.0 lib/puppet/runtime.rb
puppet-7.9.0-x86-mingw32 lib/puppet/runtime.rb
puppet-7.9.0-x64-mingw32 lib/puppet/runtime.rb
puppet-7.9.0-universal-darwin lib/puppet/runtime.rb
puppet-7.8.0 lib/puppet/runtime.rb
puppet-7.8.0-x86-mingw32 lib/puppet/runtime.rb
puppet-7.8.0-x64-mingw32 lib/puppet/runtime.rb
puppet-7.8.0-universal-darwin lib/puppet/runtime.rb
puppet-7.7.0 lib/puppet/runtime.rb
puppet-7.7.0-x86-mingw32 lib/puppet/runtime.rb
puppet-7.7.0-x64-mingw32 lib/puppet/runtime.rb
puppet-7.7.0-universal-darwin lib/puppet/runtime.rb