Class: Restforce::DB::Instances::Base
- Inherits:
-
Object
- Object
- Restforce::DB::Instances::Base
- Defined in:
- lib/restforce/db/instances/base.rb
Overview
Restforce::DB::Instances::Base defines common behavior for the other models defined in the Restforce::DB::Instances namespace.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#record_type ⇒ Object
readonly
Returns the value of attribute record_type.
Instance Method Summary collapse
-
#after_sync ⇒ Object
Public: A hook which is performed after records are synchronized.
-
#attributes ⇒ Object
Public: Get a Hash mapping the configured attributes names to their values for this instance.
-
#initialize(record_type, record, mapping = nil) ⇒ Base
constructor
Public: Initialize a new Restforce::DB::Instances::Base instance.
-
#synced? ⇒ Boolean
Public: Has this record been synced with Salesforce?.
-
#update!(attributes) ⇒ Object
Public: Update the instance with the passed attributes.
Constructor Details
#initialize(record_type, record, mapping = nil) ⇒ Base
Public: Initialize a new Restforce::DB::Instances::Base instance.
record_type - A String or Class describing the record’s type. record - The Salesforce or database record to manage. mapping - An instance of Restforce::DB::Mapping.
18 19 20 21 22 |
# File 'lib/restforce/db/instances/base.rb', line 18 def initialize(record_type, record, mapping = nil) @record_type = record_type @record = record @mapping = mapping end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
11 12 13 |
# File 'lib/restforce/db/instances/base.rb', line 11 def mapping @mapping end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
11 12 13 |
# File 'lib/restforce/db/instances/base.rb', line 11 def record @record end |
#record_type ⇒ Object (readonly)
Returns the value of attribute record_type.
11 12 13 |
# File 'lib/restforce/db/instances/base.rb', line 11 def record_type @record_type end |
Instance Method Details
#after_sync ⇒ Object
Public: A hook which is performed after records are synchronized. Override this method in subclasses to inject generic behaviors into the record synchronization flow.
Returns self.
57 58 59 |
# File 'lib/restforce/db/instances/base.rb', line 57 def after_sync self end |
#attributes ⇒ Object
Public: Get a Hash mapping the configured attributes names to their values for this instance.
Returns a Hash.
41 42 43 |
# File 'lib/restforce/db/instances/base.rb', line 41 def attributes @mapping.attributes(@record_type, record) end |
#synced? ⇒ Boolean
Public: Has this record been synced with Salesforce?
Returns a Boolean.
48 49 50 |
# File 'lib/restforce/db/instances/base.rb', line 48 def synced? true 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.
30 31 32 33 34 35 |
# File 'lib/restforce/db/instances/base.rb', line 30 def update!(attributes) return self if attributes.empty? record.update!(attributes) after_sync end |