lib/yaks/serializer/json_api.rb in yaks-0.4.0 vs lib/yaks/serializer/json_api.rb in yaks-0.4.1
- old
+ new
@@ -27,11 +27,13 @@
result
end
def serialize_links(subresources)
subresources.each_with_object({}) do |(name, resource), hsh|
- hsh[pluralize(resource.type)] = serialize_link(resource)
+ next if resource.is_a? NullResource
+ key = resource.collection? ? pluralize(resource.type) : resource.type
+ hsh[key] = serialize_link(resource)
end
end
def serialize_link(resource)
resource.collection? ? resource.map(&send_with_args(:[], :id)) : resource[:id]
@@ -51,10 +53,10 @@
# {shows => [{id: 3, name: 'foo'}]}
def serialize_subresource(resource, linked)
key = pluralize(resource.type)
set = linked.fetch(key) { Set.new }
- linked = linked[key] = (set << serialize_resource(resource))
+ linked[key] = (set << serialize_resource(resource))
serialize_linked_subresources(resource.subresources, linked)
end
end
end
end