Class: Restforce::DB::Instances::ActiveRecord
- 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
-
#after_sync ⇒ Object
Public: Bump the synchronization timestamp on the record.
-
#id ⇒ Object
Public: Get a common identifier for this record.
-
#last_update ⇒ Object
Public: Get the time of the last update to this record.
-
#synced? ⇒ Boolean
Public: Has this record been synced to a Salesforce record?.
-
#update!(attributes) ⇒ Object
Public: Update the instance with the passed attributes.
-
#updated_internally? ⇒ Boolean
Public: Was this record most recently updated by Restforce::DB’s workflow?.
-
#uuid ⇒ Object
Public: Get a unique identifier for this record.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Restforce::DB::Instances::Base
Instance Method Details
#after_sync ⇒ Object
Public: Bump the synchronization timestamp on the record.
Returns nothing.
68 69 70 71 |
# File 'lib/restforce/db/instances/active_record.rb', line 68 def after_sync @record.touch(:synchronized_at) super end |
#id ⇒ Object
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_update ⇒ Object
Public: Get the time of the last update to this record.
Returns a Time-compatible object.
46 47 48 |
# File 'lib/restforce/db/instances/active_record.rb', line 46 def last_update @record.updated_at end |
#synced? ⇒ Boolean
Public: Has this record been synced to a Salesforce record?
Returns a Boolean.
53 54 55 |
# File 'lib/restforce/db/instances/active_record.rb', line 53 def synced? @record.send(:"#{@mapping.lookup_column}?") end |
#update!(attributes) ⇒ Object
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.
36 37 38 39 40 41 |
# 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? ⇒ Boolean
Public: Was this record most recently updated by Restforce::DB’s workflow?
Returns a Boolean.
61 62 63 |
# File 'lib/restforce/db/instances/active_record.rb', line 61 def updated_internally? last_synchronize.to_i >= last_update.to_i end |
#uuid ⇒ Object
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 |