Class: ActiveForce::Mapping
- Inherits:
-
Object
- Object
- ActiveForce::Mapping
- Extended by:
- Forwardable
- Defined in:
- lib/active_force/mapping.rb
Instance Method Summary collapse
- #field(name, options) ⇒ Object
-
#initialize(model) ⇒ Mapping
constructor
A new instance of Mapping.
- #mappings ⇒ Object
- #sfdc_names ⇒ Object
- #table ⇒ Object
- #translate_to_sf(attributes) ⇒ Object
- #translate_value(value, field_name) ⇒ Object
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, fields.merge!({ name => ActiveForce::Field.new(name, ) }) end |
#mappings ⇒ Object
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_names ⇒ Object
19 20 21 |
# File 'lib/active_force/mapping.rb', line 19 def sfdc_names mappings.values end |
#table ⇒ Object
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 |