Sha256: 50ecc5e67330b25e7df6b0bdd96f67381c49bf4a3308b9b6d2ee8d116511dabd

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'gems/version'

module Gems
  module Configuration
    # An array of valid keys in the options hash when configuring a {Gems::Client}
    VALID_OPTIONS_KEYS = [
      :format,
      :user_agent,
    ]

    # The response format appended to the path if none is set
    #
    # @note JSON is preferred over XML because it is more concise and faster to parse.
    DEFAULT_FORMAT = :json

    # The value sent in the 'User-Agent' header if none is set
    DEFAULT_USER_AGENT = "Gems #{Gems::VERSION}".freeze

    attr_accessor *VALID_OPTIONS_KEYS

    # When this module is extended, set all configuration options to their default values
    def self.extended(base)
      base.reset
    end

    # Convenience method to allow configuration options to be set in a block
    def configure
      yield self
    end

    # Create a hash of options and their values
    def options
      options = {}
      VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
      options
    end

    # Reset all configuration options to defaults
    def reset
      self.format     = DEFAULT_FORMAT
      self.user_agent = DEFAULT_USER_AGENT
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gems-0.0.4 lib/gems/configuration.rb