class Restforce::Mash
def build(val, client)
appropriate Restforce::Collection, Restforce::SObject and
Pass in an Array or Hash and it will be recursively converted into the
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
def convert_value(val, duping=false)
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
def dup
def dup self.class.new(self, @client, self.default) end
def initialize(source_hash = nil, client = nil, default = nil, &blk)
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
def klass(val)
When passed a hash, it will determine what class is appropriate to
def klass(val) if val.has_key? 'records' # When the hash has a records key, it should be considered a collection # of sobject records. Restforce::Collection elsif val.has_key? 'attributes' if val['attributes']['type'] == 'Attachment' Restforce::Attachment 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