Module: AP::Configuration

Included in:
AP
Defined in:
lib/ap/configuration.rb

Overview

thanks to jnunemaker’s twitter gem for this Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash

[
:api_key,
:user_agent,
:search_query_defaults].freeze
DEFAULT_API_KEY =
nil
DEFAULT_USER_AGENT =
"Ruby AP Gem #{::AP::VERSION}".freeze
DEFAULT_SEARCH_SETTINGS =
{
  :count => 20
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



15
16
17
# File 'lib/ap/configuration.rb', line 15

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



20
21
22
# File 'lib/ap/configuration.rb', line 20

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



25
26
27
28
29
# File 'lib/ap/configuration.rb', line 25

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
  options
end

#resetObject

Reset all configuration options to defaults



40
41
42
43
44
45
# File 'lib/ap/configuration.rb', line 40

def reset
  self.api_key                = DEFAULT_API_KEY
  self.user_agent             = DEFAULT_USER_AGENT
  self.search_query_defaults  = DEFAULT_SEARCH_SETTINGS
  self
end