Class: Restforce::DB::Collector
- Inherits:
-
Object
- Object
- Restforce::DB::Collector
- 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
-
#initialize(mapping, runner = Runner.new) ⇒ Collector
constructor
Public: Initialize a new Restforce::DB::Collector.
-
#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.
Constructor Details
#initialize(mapping, runner = Runner.new) ⇒ Collector
Public: Initialize a new Restforce::DB::Collector.
mapping - A Restforce::DB::Mapping instance. runner - A Restforce::DB::Runner instance.
15 16 17 18 |
# File 'lib/restforce/db/collector.rb', line 15 def initialize(mapping, runner = Runner.new) @mapping = mapping @runner = runner end |
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.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/restforce/db/collector.rb', line 27 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 |