Module: Restforce::DB

Extended by:
Forwardable
Defined in:
lib/restforce/db.rb,
lib/restforce/db/dsl.rb,
lib/restforce/db/task.rb,
lib/restforce/db/model.rb,
lib/restforce/db/client.rb,
lib/restforce/db/runner.rb,
lib/restforce/db/worker.rb,
lib/restforce/db/adapter.rb,
lib/restforce/db/cleaner.rb,
lib/restforce/db/command.rb,
lib/restforce/db/mapping.rb,
lib/restforce/db/railtie.rb,
lib/restforce/db/tracker.rb,
lib/restforce/db/version.rb,
lib/restforce/db/attacher.rb,
lib/restforce/db/loggable.rb,
lib/restforce/db/registry.rb,
lib/restforce/db/strategy.rb,
lib/restforce/db/collector.rb,
lib/restforce/db/associator.rb,
lib/restforce/db/accumulator.rb,
lib/restforce/db/initializer.rb,
lib/restforce/db/record_cache.rb,
lib/restforce/db/synchronizer.rb,
lib/restforce/db/task_manager.rb,
lib/restforce/db/attribute_map.rb,
lib/restforce/db/configuration.rb,
lib/restforce/db/instances/base.rb,
lib/restforce/db/field_processor.rb,
lib/restforce/db/timestamp_cache.rb,
lib/restforce/db/association_cache.rb,
lib/restforce/db/associations/base.rb,
lib/restforce/db/record_types/base.rb,
lib/restforce/db/strategies/always.rb,
lib/restforce/db/strategies/passive.rb,
lib/restforce/db/associations/has_one.rb,
lib/restforce/db/instances/salesforce.rb,
lib/restforce/db/associations/has_many.rb,
lib/restforce/db/strategies/associated.rb,
lib/restforce/db/synchronization_error.rb,
lib/restforce/db/associations/belongs_to.rb,
lib/restforce/db/attribute_maps/database.rb,
lib/restforce/db/instances/active_record.rb,
lib/restforce/db/record_types/salesforce.rb,
lib/restforce/db/associations/foreign_key.rb,
lib/restforce/db/attribute_maps/salesforce.rb,
lib/restforce/db/record_types/active_record.rb,
lib/restforce/db/middleware/store_request_body.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Associations, AttributeMaps, Instances, Loggable, Middleware, Model, RecordTypes, Strategies Classes: Accumulator, Adapter, AssociationCache, Associator, Attacher, AttributeMap, Cleaner, Client, Collector, Command, Configuration, DSL, FieldProcessor, Initializer, Mapping, Railtie, RecordCache, Registry, Runner, Strategy, SynchronizationError, Synchronizer, Task, TaskManager, TaskMapping, TimestampCache, Tracker, Worker

Constant Summary collapse

HASH_DICTIONARY =

Internal: A String containing the valid suffix Hash values for a Salesforce ID.

"ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".freeze
VERSION =
"4.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Public: Get the current configuration for Restforce::DB.

Returns a Restforce::DB::Configuration instance.



79
80
81
# File 'lib/restforce/db.rb', line 79

def self.configuration
  @configuration ||= Configuration.new
end

.last_runObject

Returns the value of attribute last_run.



63
64
65
# File 'lib/restforce/db.rb', line 63

def last_run
  @last_run
end

Class Method Details

.clientObject

Public: Get a Restforce client based on the currently configured settings.

Returns a Restforce::Data::Client instance.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/restforce/db.rb', line 86

def self.client
  @client ||= begin
    DB::Client.new(
      username:       configuration.username,
      password:       configuration.password,
      security_token: configuration.security_token,
      client_id:      configuration.client_id,
      client_secret:  configuration.client_secret,
      host:           configuration.host,
      api_version:    configuration.api_version,
      timeout:        configuration.timeout,
      adapter:        configuration.adapter,
    )
  end
end

.configure {|configuration| ... } ⇒ Object

Public: Configure Restforce::DB by assigning values to the current configuration.

Yields the current configuration. Returns the current configuration.

Yields:



115
116
117
118
# File 'lib/restforce/db.rb', line 115

def self.configure
  yield(configuration)
  configuration
end

.hashed_id(salesforce_id) ⇒ Object

Public: Get the hashed version of the passed salesforce ID. This will converts 15-digit Salesforce IDs to their corresponding 18-digit version. Returns any passed 18-digit IDs back, untouched.

Returns a String. Raises an ArgumentError if the passed String is not 15 characters.

Raises:

  • (ArgumentError)


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/restforce/db.rb', line 153

def self.hashed_id(salesforce_id)
  return salesforce_id if salesforce_id.length == 18
  raise ArgumentError, "The passed Salesforce ID must be 15 or 18 characters" unless salesforce_id.length == 15

  suffixes = salesforce_id.scan(/.{5}/).map do |chunk|
    flag = 0
    chunk.split("").each_with_index do |char, idx|
      flag += (1 << idx) if char >= "A" && char <= "Z"
    end

    HASH_DICTIONARY[flag]
  end

  salesforce_id + suffixes.join
end

.resetObject

Public: Clear all globally cached values for Restforce::DB.

NOTE: This is an “idempotent” reset; following invocation, all functions should still work as before, but globally cached values will be repopulated.

Returns nothing.



127
128
129
130
131
# File 'lib/restforce/db.rb', line 127

def self.reset
  FieldProcessor.reset
  @user_id = nil
  @client = nil
end

.reset!Object

Public: Eliminate all customizations to the current Restforce::DB configuration and client.

NOTE: This is a hard reset; following invocation, Restforce::DB will need to be reconfigured in order for functionality to be restored.

Returns nothing.



140
141
142
143
144
145
# File 'lib/restforce/db.rb', line 140

def self.reset!
  reset

  @configuration = nil
  @last_run = nil
end

.user_idObject

Public: Get the ID of the Salesforce user which is being used to access the Salesforce API.

Returns a String.



106
107
108
# File 'lib/restforce/db.rb', line 106

def self.user_id
  @user_id ||= client..user_id
end