Class: Restforce::DB::Registry

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/restforce/db/registry.rb

Overview

Restforce::DB::Registry is responsible for keeping track of all mappings established in the system.

Class Method Summary collapse

Class Method Details

.<<(mapping) ⇒ Object

Public: Add a mapping to the overarching Mapping collection. Appends the mapping to the collection for both its database and salesforce object types.

mapping - A Restforce::DB::Mapping.

Returns nothing.



43
44
45
46
47
# File 'lib/restforce/db/registry.rb', line 43

def self.<<(mapping)
  [mapping.database_model, mapping.salesforce_model].each do |model|
    collection[model] << mapping
  end
end

.[](model) ⇒ Object

Public: Get the Restforce::DB::Mapping entry for the specified model.

model - A String or Class.

Returns a Restforce::DB::Mapping.



16
17
18
# File 'lib/restforce/db/registry.rb', line 16

def self.[](model)
  collection[model]
end

.clean!Object

Public: Clear out any existing registered mappings.

Returns nothing.



52
53
54
# File 'lib/restforce/db/registry.rb', line 52

def self.clean!
  @collection = nil
end

.collectionObject

Public: Get the collection of currently-registered mappings.

Returns a Hash.



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

def self.collection
  @collection ||= Hash.new { |h, k| h[k] = [] }
end

.eachObject

Public: Iterate through all registered Restforce::DB::Mappings.

Yields one Mapping for each database-to-Salesforce mapping. Returns nothing.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/restforce/db/registry.rb', line 24

def self.each
  collection.each do |model, mappings|
    # Since each mapping is inserted twice, we ignore the half which
    # were inserted via Salesforce model names.
    next unless model.is_a?(Class)

    mappings.each do |mapping|
      yield mapping
    end
  end
end