Sha256: ee7969f3c41a86f705250433d24fe241759709aec264d1d6c6bd788f703da472
Contents?: true
Size: 896 Bytes
Versions: 17
Compression:
Stored size: 896 Bytes
Contents
# frozen_string_literal: true module Dato class JsonApiDeserializer def deserialize(data) data = data[:data] if data.is_a? Array data.map { |resource| deserialize_resource(resource) } else deserialize_resource(data) end end def deserialize_resource(data) result = { id: data[:id] } if data[:attributes] result.merge!(data[:attributes]) end relationships = data.delete(:relationships) if relationships relationships.each do |key, handle| handle_data = handle['data'] value = if handle_data.is_a? Array handle_data.map { |ref| ref['id'] } elsif handle_data.is_a? Hash handle_data[:id] end result[key] = value end end result.with_indifferent_access end end end
Version data entries
17 entries across 17 versions & 1 rubygems