Class: Restforce::DB::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/restforce/db/configuration.rb

Overview

Restforce::DB::Configuration exposes a handful of straightforward write and read methods to allow users to configure Restforce::DB.

Constant Summary collapse

DEFAULT_API_VERSION =
"29.0".freeze
DEFAULT_TIMEOUT =
5.freeze
DEFAULT_ADAPTER =
:net_http.freeze

Instance Method Summary collapse

Instance Method Details

#before(*args, &block) ⇒ Object

Public: Allow a ‘before` callback to be configured or run. Runs the previously-configured block with any passed objects if called without a block.

args - An arbitrary collection of arguments to pass to the hook. block - A block of code to execute after process forking.

Returns nothing.



36
37
38
39
40
41
42
# File 'lib/restforce/db/configuration.rb', line 36

def before(*args, &block)
  if block_given?
    Thread.current[:before_hook] = block
  else
    Thread.current[:before_hook].call(*args) if Thread.current[:before_hook]
  end
end

#load(configurations) ⇒ Object

Public: Populate this configuration object from a Hash of credentials.

configurations - A Hash of credentials, with keys matching the names

of the attributes for this class.

Returns nothing.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/restforce/db/configuration.rb', line 69

def load(configurations)
  self.username       = parsed(configurations, "username")
  self.password       = parsed(configurations, "password")
  self.security_token = parsed(configurations, "security_token")
  self.client_id      = parsed(configurations, "client_id")
  self.client_secret  = parsed(configurations, "client_secret")
  self.host           = parsed(configurations, "host")

  # We want to default to 29.0 or later, so we can support the API
  # endpoint for recently deleted records.
  self.api_version    = configurations["api_version"] || DEFAULT_API_VERSION
  self.timeout        = configurations["timeout"] || DEFAULT_TIMEOUT
  self.adapter        = (configurations["adapter"] || DEFAULT_ADAPTER).to_sym
end

#loggerObject

Public: Get the configured logger. Returns a null logger if no logger has been configured yet.

Returns a Logger.



48
49
50
# File 'lib/restforce/db/configuration.rb', line 48

def logger
  @logger ||= Logger.new("/dev/null")
end

#parse(file_path) ⇒ Object

Public: Parse a supplied YAML file for a set of credentials, and use them to populate the attributes on this configuraton object.

file_path - A String or Path referencing a client configuration file.

Returns nothing.



58
59
60
61
# File 'lib/restforce/db/configuration.rb', line 58

def parse(file_path)
  settings = YAML.load_file(file_path)
  load(settings["client"])
end