Class: Restforce::DB::Instances::Base

Inherits:
Object
  • Object
show all
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

ActiveRecord, Salesforce

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#mappingObject (readonly)

Returns the value of attribute mapping.



11
12
13
# File 'lib/restforce/db/instances/base.rb', line 11

def mapping
  @mapping
end

#recordObject (readonly)

Returns the value of attribute record.



11
12
13
# File 'lib/restforce/db/instances/base.rb', line 11

def record
  @record
end

#record_typeObject (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_syncObject

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

#attributesObject

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.

Returns:

  • (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