Module: Draisine::ActiveRecordMacro

Defined in:
lib/draisine/active_record.rb

Instance Method Summary collapse

Instance Method Details

#salesforce_syncable(options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/draisine/active_record.rb', line 6

def salesforce_syncable(options)
  include Draisine::ActiveRecordPlugin

  self.salesforce_object_name = options.fetch(:salesforce_object_name, name)
  salesforce_synced_attributes = options.fetch(:synced_attributes, []).map(&:to_s)
  default_mapping = salesforce_synced_attributes.map {|k| [k, k] }.to_h
  mapping = options.fetch(:mapping, {}).map {|k,v| [k.to_s, v.to_s] }.to_h
  self.salesforce_mapping = default_mapping.merge(mapping)
  self.salesforce_ops = Set.new(options.fetch(:operations, ALL_OPS))
  self.salesforce_sync_mode = options.fetch(:sync, true)
  non_audited_attrs = options.fetch(:non_audited_attributes, []).map(&:to_s)
  self.salesforce_audited_attributes = salesforce_synced_attributes - non_audited_attrs

  options.fetch(:array_attributes, []).each do |attr|
    salesforce_array_setter(attr)
  end

  Draisine.registry.register(self, salesforce_object_name)
end