Sha256: 7c6eac7f85a0512df9ea278239b7005ad1e03a0b38b68c517d7f8a198e57061c

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'roe/version'

module Roe
  # Defines constants and methods related to configuration
  module Configuration
    # An array of valid keys in the options hash on configuration
    VALID_OPTIONS_KEYS = [
      :adapter,
      :proxy,
      :user_agent,
      :connection_options].freeze

    # The adapter that will be used to connect if none is set
    DEFAULT_ADAPTER = :net_http

    # By default, don't use a proxy server
    DEFAULT_PROXY = nil

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

    DEFAULT_CONNECTION_OPTIONS = {}.freeze

    # @private
    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.adapter            = DEFAULT_ADAPTER
      self.proxy              = DEFAULT_PROXY
      self.user_agent         = DEFAULT_USER_AGENT
      self.connection_options = DEFAULT_CONNECTION_OPTIONS
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roe-0.1.0 lib/roe/configuration.rb