Class: Restforce::DB::Instances::ActiveRecord

Inherits:
Base
  • Object
show all
Defined in:
lib/restforce/db/instances/active_record.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Base

#mapping, #record, #record_type

Instance Method Summary collapse

Methods inherited from Base

#attributes, #initialize, #update!

Constructor Details

This class inherits a constructor from Restforce::DB::Instances::Base

Instance Method Details

#after_syncObject

Public: Bump the synchronization timestamp on the record.

Returns nothing.



55
56
57
58
# File 'lib/restforce/db/instances/active_record.rb', line 55

def after_sync
  @record.touch(:synchronized_at)
  super
end

#idObject

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

Returns a String.



16
17
18
19
# File 'lib/restforce/db/instances/active_record.rb', line 16

def id
  return uuid unless synced?
  @record.send(@mapping.lookup_column)
end

#last_updateObject

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

Returns a Time-compatible object.



33
34
35
# File 'lib/restforce/db/instances/active_record.rb', line 33

def last_update
  @record.updated_at
end

#synced?Boolean

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

Returns a Boolean.

Returns:

  • (Boolean)


40
41
42
# File 'lib/restforce/db/instances/active_record.rb', line 40

def synced?
  @record.send(:"#{@mapping.lookup_column}?")
end

#updated_internally?Boolean

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

Returns a Boolean.

Returns:

  • (Boolean)


48
49
50
# File 'lib/restforce/db/instances/active_record.rb', line 48

def updated_internally?
  last_synchronize.to_i >= last_update.to_i
end

#uuidObject

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

Returns nothing.



26
27
28
# File 'lib/restforce/db/instances/active_record.rb', line 26

def uuid
  "#{@record_type}::#{@record.id}"
end