lib/dato/json_api_deserializer.rb in dato-0.1.5 vs lib/dato/json_api_deserializer.rb in dato-0.1.6

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true module Dato class JsonApiDeserializer def deserialize(data) data = data[:data] @@ -15,23 +16,20 @@ result.merge!(data[:attributes]) relationships = data.delete(:relationships) if relationships - relationships.each do |key, data| - data = data["data"] - value = if data.is_a? Array - data.map { |ref| ref["id"] } - elsif data.is_a? Hash - data[:id] - else - nil + 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 -