Module: Draisine::Concerns::AttributesMapping
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveRecordPlugin
- Defined in:
- lib/draisine/concerns/attributes_mapping.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #salesforce_assign_attributes(attributes) ⇒ Object
- #salesforce_attributes ⇒ Object
- #salesforce_mapped_attributes(attributes, mapping = self.class.salesforce_mapping) ⇒ Object
- #salesforce_reverse_mapped_attributes(attributes) ⇒ Object
Instance Method Details
#salesforce_assign_attributes(attributes) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/draisine/concerns/attributes_mapping.rb', line 26 def salesforce_assign_attributes(attributes) salesforce_mapped_attributes(attributes.with_indifferent_access).each do |key, value| method_name = "#{key}=" if respond_to?(method_name) value = Draisine::SalesforceComparisons.salesforce_cleanup(value) __send__(method_name, value) end end end |
#salesforce_attributes ⇒ Object
40 41 42 43 |
# File 'lib/draisine/concerns/attributes_mapping.rb', line 40 def salesforce_attributes salesforce_reverse_mapped_attributes(attributes) .with_indifferent_access end |
#salesforce_mapped_attributes(attributes, mapping = self.class.salesforce_mapping) ⇒ Object
20 21 22 23 24 |
# File 'lib/draisine/concerns/attributes_mapping.rb', line 20 def salesforce_mapped_attributes(attributes, mapping = self.class.salesforce_mapping) attributes.slice(*mapping.keys).each_with_object({}) do |(key, value), acc| acc[mapping.fetch(key)] = value end end |
#salesforce_reverse_mapped_attributes(attributes) ⇒ Object
36 37 38 |
# File 'lib/draisine/concerns/attributes_mapping.rb', line 36 def salesforce_reverse_mapped_attributes(attributes) salesforce_mapped_attributes(attributes, self.class.salesforce_reverse_mapping) end |