Class: Restforce::DB::FieldProcessor
- Inherits:
-
Object
- Object
- Restforce::DB::FieldProcessor
- Defined in:
- lib/restforce/db/field_processor.rb
Overview
Restforce::DB::FieldProcessor encapsulates logic for preventing information for unwriteable fields from being submitted to Salesforce.
Class Method Summary collapse
-
.field_cache ⇒ Object
Internal: Get a global cache with which to store/fetch the writable fields for each Salesforce SObject Type.
-
.reset ⇒ Object
Internal: Clear out the global field cache.
Instance Method Summary collapse
-
#process(sobject_type, attributes, write_type = :update) ⇒ Object
Public: Get a restricted version of the passed attributes Hash, with unwritable fields stripped out.
Class Method Details
.field_cache ⇒ Object
Internal: Get a global cache with which to store/fetch the writable fields for each Salesforce SObject Type.
Returns a Hash.
13 14 15 |
# File 'lib/restforce/db/field_processor.rb', line 13 def self.field_cache @field_cache ||= {} end |
.reset ⇒ Object
Internal: Clear out the global field cache.
Returns nothing.
20 21 22 |
# File 'lib/restforce/db/field_processor.rb', line 20 def self.reset @field_cache = {} end |
Instance Method Details
#process(sobject_type, attributes, write_type = :update) ⇒ Object
Public: Get a restricted version of the passed attributes Hash, with unwritable fields stripped out.
sobject_type - A String name of an SObject Type in Salesforce. attributes - A Hash with keys corresponding to Salesforce field names. write_type - A Symbol reflecting the type of write operation. Accepted
values are :create and :update. Defaults to :update.
Returns a Hash.
33 34 35 36 37 38 |
# File 'lib/restforce/db/field_processor.rb', line 33 def process(sobject_type, attributes, write_type = :update) attributes.each_with_object({}) do |(field, value), processed| next unless writable?(sobject_type, field, write_type) processed[field] = value end end |