Module: Bob::Configuration

Included in:
Bob
Defined in:
lib/bob/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
%i[access_token access_user_name api_version api_key use_sandbox custom_tables custom_fields
default_custom_fields].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.



11
12
13
# File 'lib/bob/configuration.rb', line 11

def self.extended(base)
  base.reset
end

Instance Method Details

#configObject



19
20
21
22
23
# File 'lib/bob/configuration.rb', line 19

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

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

Yields:

  • (_self)

Yield Parameters:



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

def configure
  yield self
end

#resetObject

Resets all configuration options to the defaults.



26
27
28
29
30
31
32
33
34
35
# File 'lib/bob/configuration.rb', line 26

def reset
  self.api_version = 'v1'
  self.access_token = ENV.fetch('ACCESS_TOKEN', nil)
  self.access_user_name = ENV.fetch('ACCESS_USER_NAME', nil)
  self.api_key = ENV.fetch('API_KEY', nil)
  self.use_sandbox = false
  self.custom_tables = {}
  self.custom_fields = {}
  self.default_custom_fields = []
end