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.
Constant Summary collapse
- RELATIONSHIP_MATCHER =
This token indicates that a relationship is being accessed for a specific field.
/(.+)__r\./.freeze
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
-
#available_fields(sobject_type, fields, action = :read) ⇒ Object
Public: Get a list of valid fields for a specific action from the passed list of proposed fields.
-
#process(sobject_type, attributes, action) ⇒ Object
Public: Get a restricted version of the passed attributes Hash, with inaccessible fields for the specified action 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.
17 18 19 |
# File 'lib/restforce/db/field_processor.rb', line 17 def self.field_cache @field_cache ||= {} end |
.reset ⇒ Object
Internal: Clear out the global field cache.
Returns nothing.
24 25 26 |
# File 'lib/restforce/db/field_processor.rb', line 24 def self.reset @field_cache = {} end |
Instance Method Details
#available_fields(sobject_type, fields, action = :read) ⇒ Object
Public: Get a list of valid fields for a specific action from the passed list of proposed fields. Allows access to related object fields on a read-only basis.
sobject_type - A String name of an SObject Type in Salesforce. attributes - A Hash with keys corresponding to Salesforce field names. action - A Symbol reflecting the action to perform. Accepted
values are :read, :create, and :update.
Returns a Hash.
38 39 40 41 42 43 44 45 |
# File 'lib/restforce/db/field_processor.rb', line 38 def available_fields(sobject_type, fields, action = :read) fields.select do |field| known_field = available?(sobject_type, field, action) relationship = action == :read && relationship?(field) known_field || relationship end end |
#process(sobject_type, attributes, action) ⇒ Object
Public: Get a restricted version of the passed attributes Hash, with inaccessible fields for the specified action stripped out.
sobject_type - A String name of an SObject Type in Salesforce. attributes - A Hash with keys corresponding to Salesforce field names. action - A Symbol reflecting the action to perform. Accepted
values are :create and :update.
Returns a Hash.
56 57 58 |
# File 'lib/restforce/db/field_processor.rb', line 56 def process(sobject_type, attributes, action) attributes.select { |field, _| available?(sobject_type, field, action) } end |