Created
January 24, 2020 17:46
-
-
Save jeffdonthemic/8219a17432b57301c839c61198df5999 to your computer and use it in GitHub Desktop.
Restforce monkey patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Restforce | |
| class Mash < Hashie::Mash | |
| class << self | |
| def klass(val) | |
| if val.key? 'records' | |
| # When the hash has a records key, it should be considered a collection | |
| # of sobject records. | |
| Restforce::Collection | |
| elsif val.key? 'attributes' | |
| case val.dig('attributes', 'type') | |
| when "Attachment" | |
| Restforce::Attachment | |
| when "Document" | |
| Restforce::Document | |
| else | |
| # When the hash contains an attributes key, it should be considered an | |
| # sobject record | |
| Restforce::SObject | |
| end | |
| else | |
| # Fallback to a standard Restforce::Mash for everything else | |
| Restforce::Mash | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment