Sha256: 45cac211fceef915b952f516c8d7d502047009380331bd4b31d7f62d1aeed570
Contents?: true
Size: 881 Bytes
Versions: 12
Compression:
Stored size: 881 Bytes
Contents
module ForestLiana class ResourceDeserializer def initialize(resource, params) @params = params @resource = resource end def perform @attributes = extract_attributes extract_relationships @attributes end def extract_attributes @params['data']['attributes'] end def extract_relationships if @params['data']['relationships'] @params['data']['relationships'].each do |name, relationship| data = relationship['data'] if column?(name.foreign_key) if data.is_a?(Hash) @attributes[name.foreign_key] = data[:id] elsif !data @attributes[name.foreign_key] = nil end end end end end def column?(attribute) @resource.columns.find {|x| x.name == attribute}.present? end end end
Version data entries
12 entries across 12 versions & 1 rubygems