Class: Sfdc::Mash
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Sfdc::Mash
- Defined in:
- lib/sfdc/mash.rb
Direct Known Subclasses
Class Method Summary collapse
-
.build(val, client) ⇒ Object
Pass in an Array or Hash and it will be recursively converted into the appropriate Sfdc::Collection, Sfdc::SObject and Sfdc::Mash objects.
-
.klass(val) ⇒ Object
When passed a hash, it will determine what class is appropriate to represent the data.
Instance Method Summary collapse
- #convert_value(val, duping = false) ⇒ Object
- #dup ⇒ Object
-
#initialize(source_hash = nil, client = nil, default = nil, &blk) ⇒ Mash
constructor
A new instance of Mash.
Constructor Details
#initialize(source_hash = nil, client = nil, default = nil, &blk) ⇒ Mash
Returns a new instance of Mash.
44 45 46 47 48 |
# File 'lib/sfdc/mash.rb', line 44 def initialize(source_hash = nil, client = nil, default = nil, &blk) @client = client deep_update(source_hash) if source_hash default ? super(default) : super(&blk) end |
Class Method Details
.build(val, client) ⇒ Object
Pass in an Array or Hash and it will be recursively converted into the appropriate Sfdc::Collection, Sfdc::SObject and Sfdc::Mash objects.
11 12 13 14 15 16 17 18 19 |
# File 'lib/sfdc/mash.rb', line 11 def build(val, client) if val.is_a?(Array) val.collect { |val| self.build(val, client) } elsif val.is_a?(Hash) self.klass(val).new(val, client) else val end end |
.klass(val) ⇒ Object
When passed a hash, it will determine what class is appropriate to represent the data.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sfdc/mash.rb', line 23 def klass(val) if val.has_key? 'records' # When the hash has a records key, it should be considered a collection # of sobject records. Sfdc::Collection elsif val.has_key? 'attributes' if val['attributes']['type'] == 'Attachment' Sfdc::Attachment else # When the hash contains an attributes key, it should be considered an # sobject record Sfdc::SObject end else # Fallback to a standard Sfdc::Mash for everything else Sfdc::Mash end end |
Instance Method Details
#convert_value(val, duping = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sfdc/mash.rb', line 54 def convert_value(val, duping=false) case val when self.class val.dup when ::Hash val = val.dup if duping self.class.klass(val).new(val, @client) when Array val.collect{ |e| convert_value(e) } else val end end |
#dup ⇒ Object
50 51 52 |
# File 'lib/sfdc/mash.rb', line 50 def dup self.class.new(self, @client, self.default) end |