Class: ActiveForce::Mapping

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

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Mapping

Returns a new instance of Mapping.



11
12
13
# File 'lib/active_force/mapping.rb', line 11

def initialize model
  @model = model
end

Instance Method Details

#field(name, options) ⇒ Object



23
24
25
# File 'lib/active_force/mapping.rb', line 23

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

#mappingsObject



15
16
17
# File 'lib/active_force/mapping.rb', line 15

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

#sfdc_namesObject



19
20
21
# File 'lib/active_force/mapping.rb', line 19

def sfdc_names
  mappings.values
end

#tableObject



27
28
29
# File 'lib/active_force/mapping.rb', line 27

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

#translate_to_sf(attributes) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/active_force/mapping.rb', line 31

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

#translate_value(value, field_name) ⇒ Object



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

def translate_value value, field_name
  return value unless !!field_name
  value
end