class Restforce::DB::Instances::ActiveRecord

Restforce::DB::Instances::ActiveRecord serves as a wrapper for ActiveRecord::Base-compatible objects, exposing a common API to reconcile record attributes with Salesforce instances.

Public Instance Methods

after_sync() click to toggle source

Public: Bump the synchronization timestamp on the record.

Returns nothing.

Calls superclass method
# File lib/restforce/db/instances/active_record.rb, line 68
def after_sync
  @record.touch(:synchronized_at)
  super
end
id() click to toggle source

Public: Get a common identifier for this record. If the record is unsynchronized, returns a database-specific identifier.

Returns a String.

# File lib/restforce/db/instances/active_record.rb, line 16
def id
  return uuid unless synced?
  @record.send(@mapping.lookup_column)
end
last_update() click to toggle source

Public: Get the time of the last update to this record.

Returns a Time-compatible object.

# File lib/restforce/db/instances/active_record.rb, line 46
def last_update
  @record.updated_at
end
synced?() click to toggle source

Public: Has this record been synced to a Salesforce record?

Returns a Boolean.

# File lib/restforce/db/instances/active_record.rb, line 53
def synced?
  @record.send(:"#{@mapping.lookup_column}?")
end
update!(attributes) click to toggle source

Public: Update the instance with the passed attributes.

attributes - A Hash mapping attribute names to values.

Returns self. Raises if the update fails for any reason.

Calls superclass method
# File lib/restforce/db/instances/active_record.rb, line 36
def update!(attributes)
  record.assign_attributes(attributes)
  return self unless record.changed?

  super attributes
end
updated_internally?() click to toggle source

Public: Was this record most recently updated by Restforce::DB's workflow?

Returns a Boolean.

# File lib/restforce/db/instances/active_record.rb, line 61
def updated_internally?
  last_synchronize.to_i >= last_update.to_i
end
uuid() click to toggle source

Public: Get a unique identifier for this record. This value should be consistent for the specific ActiveRecord object passed to this instance.

Returns nothing.

# File lib/restforce/db/instances/active_record.rb, line 26
def uuid
  "#{@record_type}::#{@record.id}"
end

Private Instance Methods

last_synchronize() click to toggle source

Internal: Get the time of the last synchronization update to this record.

Returns a Time-compatible object.

# File lib/restforce/db/instances/active_record.rb, line 79
def last_synchronize
  @record.synchronized_at
end