Class: Restforce::DB::Collector

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

Overview

Restforce::DB::Collector is responsible for grabbing the attributes from recently-updated records for purposes of synchronization. It relies on the mappings configured in instances of Restforce::DB::RecordTypes::Base to locate recently-updated records and fetch their attributes.

Instance Method Summary collapse

Methods inherited from Task

#initialize

Constructor Details

This class inherits a constructor from Restforce::DB::Task

Instance Method Details

#run(accumulator = nil) ⇒ Object

Public: Run the collection process, pulling in records from Salesforce and the database to determine the lists of attributes to apply to all mapped records.

accumulator - A Hash-like accumulator object.

Returns a Hash mapping Salesforce ID/type combinations to accumulators.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/restforce/db/collector.rb', line 18

def run(accumulator = nil)
  @accumulated_changes = accumulator || accumulated_changes

  @runner.run(@mapping) do |run|
    run.salesforce_instances.each { |instance| accumulate(instance) }
    run.database_instances.each { |instance| accumulate(instance) }
  end

  accumulated_changes
ensure
  # Clear out the results of this run so we start fresh next time.
  @accumulated_changes = nil
end