Class: ActiveForce::Mapping

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/active_force/mapping.rb

Constant Summary collapse

STRINGLIKE_TYPES =
[
  nil, :string, :base64, :byte, :ID, :reference, :currency, :textarea,
  :phone, :url, :email, :combobox, :picklist, :multipicklist, :anyType,
  :location
]

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Mapping

Returns a new instance of Mapping.



17
18
19
# File 'lib/active_force/mapping.rb', line 17

def initialize model
  @model = model
end

Instance Method Details

#field(name, options) ⇒ Object



29
30
31
# File 'lib/active_force/mapping.rb', line 29

def field name, options
  fields.merge!({ name => ActiveForce::Attribute.new(name, options) })
end

#mappingsObject



21
22
23
# File 'lib/active_force/mapping.rb', line 21

def mappings
  Hash[fields.map { |field, attr| [field, attr.sfdc_name] }]
end

#sfdc_namesObject



25
26
27
# File 'lib/active_force/mapping.rb', line 25

def sfdc_names
  mappings.values
end

#tableObject



33
34
35
# File 'lib/active_force/mapping.rb', line 33

def table
  @table ||= ActiveForce::Table.new @model
end

#translate_to_sf(attributes) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/active_force/mapping.rb', line 37

def translate_to_sf attributes
  attrs = attributes.map do |attribute, value|
    attr = fields[attribute.to_sym]
    [attr.sfdc_name, attr.value_for_hash(value)]
  end
  Hash[attrs]
end

#translate_value(value, field_name) ⇒ Object



45
46
47
48
# File 'lib/active_force/mapping.rb', line 45

def translate_value value, field_name
  return value unless !!field_name
  typecast_value value, fields[field_name].as
end