class Restforce::DB::Accumulator

Restforce::DB::Accumulator is responsible for the accumulation of changes over the course of a single synchronization run. As we iterate over the various mappings, we build a set of changes for each Salesforce ID, which is then applied to all objects synchronized with that Salesforce object.

Public Instance Methods

attributes() click to toggle source

Public: Get the accumulated list of attributes after all changes have been applied.

Returns a Hash.

# File lib/restforce/db/accumulator.rb, line 28
def attributes
  @attributes ||= sort.reverse.inject({}) do |final, (_, changeset)|
    changeset.merge(final)
  end
end
changed?(comparison) click to toggle source

Public: Do the canonical attributes stored in this Accumulator differ from those in the passed comparison Hash?

comparison - A Hash mapping of attributes to values.

Returns a Boolean.

# File lib/restforce/db/accumulator.rb, line 53
def changed?(comparison)
  attributes.any? do |attribute, value|
    next unless comparison.key?(attribute)
    comparison[attribute] != value
  end
end
current(comparison) click to toggle source

Public: Get a Hash representing the current values for the items in the passed Hash, as a subset of this Accumulator's attributes Hash.

comparison - A Hash mapping of attributes to values.

Returns a Hash.

# File lib/restforce/db/accumulator.rb, line 40
def current(comparison)
  attributes.each_with_object({}) do |(attribute, value), final|
    next unless comparison.key?(attribute)
    final[attribute] = value
  end
end
store(timestamp, changeset) click to toggle source

Public: Store the changeset under the given timestamp. If a changeset for that timestamp has already been registered, merge it with the newly passed changeset.

timestamp - A Time object. changeset - A Hash mapping attribute names to values.

Returns nothing.

Calls superclass method
# File lib/restforce/db/accumulator.rb, line 19
def store(timestamp, changeset)
  return super unless key?(timestamp)
  self[timestamp].merge!(changeset)
end
up_to_date_for?(timestamp) click to toggle source

Public: Does the timestamp of the most recent change meet or exceed the specified timestamp?

timestamp - A Time object.

Returns a Boolean.

# File lib/restforce/db/accumulator.rb, line 66
def up_to_date_for?(timestamp)
  keys.sort.last >= timestamp
end