First try to implement ArraySerializer

This commit is contained in:
Tema Bolshakov
2014-08-28 19:16:24 +04:00
parent 1b718b6d48
commit c1fdfc1cdc
6 changed files with 46 additions and 45 deletions

View File

@@ -3,20 +3,21 @@ module ActiveModel
class Adapter
class JsonApiAdapter < Adapter
def serializable_hash(options = {})
hash = serializer.attributes.each_with_object({}) do |(attr, value), h|
h[attr] = value
end
hash = serializer.attributes
serializer.associations(only: [:id]).each_with_object({}) do |(attr, value), h|
case value
when ActiveModel::Serializer::ArraySerializer
# process has_many association
when ActiveModel::Serializer
# process belongs_to association
else
# what?
end
associations = serializer.associations(only: [:id]).each_with_object({}) do |(attr, value), h|
h[attr] = case value
when ActiveModel::Serializer::ArraySerializer
value.attributes(options).map do |item|
item.id
end.to_a
when ActiveModel::Serializer
# process belongs_to association
else
# what?
end
end
hash.merge(associations)
end
end
end