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 Attribute Summary collapse
-
#last_run ⇒ Object
readonly
Returns the value of attribute last_run.
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.
17 18 19 20 |
# File 'lib/restforce/db/collector.rb', line 17 def initialize(mapping, runner = Runner.new) @mapping = mapping @runner = runner end |
Instance Attribute Details
#last_run ⇒ Object (readonly)
Returns the value of attribute last_run.
11 12 13 |
# File 'lib/restforce/db/collector.rb', line 11 def last_run @last_run 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.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/restforce/db/collector.rb', line 29 def run(accumulator = nil) @accumulated_changes = accumulator || accumulated_changes @runner.run(@mapping) do |run| run.salesforce_records { |record| accumulate(record) } run.database_records { |record| accumulate(record) } end accumulated_changes ensure # Clear out the results of this run so we start fresh next time. @accumulated_changes = nil end |