Sha256: 98f881beb3aece3e53940e2d26c3066529b86b1b09faa4b55b5497194aaf8ae0

Contents?: true

Size: 1.62 KB

Versions: 8

Compression:

Stored size: 1.62 KB

Contents

module ChefAPI
  #
  # A re-usable class containing configuration information for the {Connection}.
  # See {Defaults} for a list of default values.
  #
  module Configurable
    class << self
      #
      # The list of configurable keys.
      #
      # @return [Array<Symbol>]
      #
      def keys
        @keys ||= %i{
          endpoint
          flavor
          client
          key
          proxy_address
          proxy_password
          proxy_port
          proxy_username
          ssl_pem_file
          ssl_verify
          user_agent
          read_timeout
        }
      end
    end

    #
    # Create one attribute getter and setter for each key.
    #
    ChefAPI::Configurable.keys.each do |key|
      attr_accessor key
    end

    #
    # Set the configuration for this config, using a block.
    #
    # @example Configure the API endpoint
    #   ChefAPI.configure do |config|
    #     config.endpoint = "http://www.my-ChefAPI-server.com/ChefAPI"
    #   end
    #
    def configure
      yield self
    end

    #
    # Reset all configuration options to their default values.
    #
    # @example Reset all settings
    #   ChefAPI.reset!
    #
    # @return [self]
    #
    def reset!
      ChefAPI::Configurable.keys.each do |key|
        instance_variable_set(:"@#{key}", Defaults.options[key])
      end
      self
    end
    alias_method :setup, :reset!

    private

    #
    # The list of configurable keys, as an options hash.
    #
    # @return [Hash]
    #
    def options
      map = ChefAPI::Configurable.keys.map do |key|
        [key, instance_variable_get(:"@#{key}")]
      end
      Hash[map]
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
chef-infra-api-0.10.10 lib/chef-api/configurable.rb
chef-api-0.10.10 lib/chef-api/configurable.rb
chef-infra-api-0.10.7 lib/chef-api/configurable.rb
chef-api-0.10.7 lib/chef-api/configurable.rb
chef-infra-api-0.10.5 lib/chef-api/configurable.rb
chef-api-0.10.5 lib/chef-api/configurable.rb
chef-infra-api-0.10.2 lib/chef-api/configurable.rb
chef-api-0.10.2 lib/chef-api/configurable.rb