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