Module: Brat::Configuration

Included in:
Brat
Defined in:
lib/brat/configuration.rb

Overview

Defines constants and methods related to configuration.

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a Brat::API.

[:endpoint, :private_token, :user_agent, :sudo,
:namespace, :api_version, :host].freeze
DEFAULT_USER_AGENT =

The user agent that will be sent to the API endpoint if none is set.

"Brat Ruby Gem #{Brat::VERSION}".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Sets all configuration options to their default values when this module is extended.



16
17
18
# File 'lib/brat/configuration.rb', line 16

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:



21
22
23
# File 'lib/brat/configuration.rb', line 21

def configure
  yield self
end

#optionsObject

Creates a hash of options and their values.



26
27
28
29
30
# File 'lib/brat/configuration.rb', line 26

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Resets all configuration options to the defaults.



33
34
35
36
37
38
# File 'lib/brat/configuration.rb', line 33

def reset
  self.endpoint       = 'http://brat.io/api/v3'
  self.private_token  = ENV['BRAT_API_PRIVATE_TOKEN']
  self.sudo           = nil
  self.user_agent     = DEFAULT_USER_AGENT
end