class Restforce::DB::Instances::Base

Restforce::DB::Instances::Base defines common behavior for the other models defined in the Restforce::DB::Instances namespace.

Attributes

mapping[R]
record[R]
record_type[R]

Public Class Methods

new(record_type, record, mapping = nil) click to toggle source

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.

# 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

Public Instance Methods

after_sync() click to toggle source

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.

# File lib/restforce/db/instances/base.rb, line 57
def after_sync
  self
end
attributes() click to toggle source

Public: Get a Hash mapping the configured attributes names to their values for this instance.

Returns a Hash.

# File lib/restforce/db/instances/base.rb, line 41
def attributes
  @mapping.attributes(@record_type, record)
end
synced?() click to toggle source

Public: Has this record been synced with Salesforce?

Returns a Boolean.

# File lib/restforce/db/instances/base.rb, line 48
def synced?
  true
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.

# File lib/restforce/db/instances/base.rb, line 30
def update!(attributes)
  return self if attributes.empty?

  record.update!(attributes)
  after_sync
end