class Restforce::DB::Configuration

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

Constants

DEFAULT_ADAPTER
DEFAULT_API_VERSION
DEFAULT_TIMEOUT

Public Instance Methods

before(*args, &block) click to toggle source

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.

# 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) click to toggle source

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.

# 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
logger() click to toggle source

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

Returns a Logger.

# File lib/restforce/db/configuration.rb, line 48
def logger
  @logger ||= Logger.new("/dev/null")
end
parse(file_path) click to toggle source

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.

# File lib/restforce/db/configuration.rb, line 58
def parse(file_path)
  settings = YAML.load_file(file_path)
  load(settings["client"])
end

Private Instance Methods

parsed(configurations, setting) click to toggle source

Internal: Get the requested setting from a Hash of configurations.

configurations - A Hash of configurations. setting - A String name of a single configuration in the Hash.

Returns the value of the setting. Raises ArgumentError if the setting is not contained in the Hash.

# File lib/restforce/db/configuration.rb, line 93
def parsed(configurations, setting)
  configurations.fetch setting do |key|
    raise ArgumentError, "Configuration is missing #{key}"
  end
end