lib/dato/json_api_serializer.rb in dato-0.6.3.beta vs lib/dato/json_api_serializer.rb in dato-0.6.3

- old
+ new

@@ -42,10 +42,11 @@ result = {} relationships.each do |relationship, meta| if resource.key? relationship value = resource[relationship] + data = if value if meta[:collection] value.map do |id| { type: meta[:type], id: id.to_s } end @@ -63,29 +64,39 @@ result end def attributes(resource) if type == "item" - resource.keys - [:item_type, :id] + return resource.keys.map(&:to_sym) - [ + :item_type, + :id, + :created_at, + :updated_at, + :is_valid, + :published_version, + :current_version + ] end link_attributes["properties"].keys.map(&:to_sym) end def required_attributes if type == "item" - [] + return [] end (link_attributes.required || []).map(&:to_sym) end def relationships if type == "item" - { - item_type: { collection: false, type: 'item_type' } - } + if link.rel == :create + return { item_type: { collection: false, type: 'item_type' } } + else + {} + end end if !link_relationships return {} end @@ -108,15 +119,17 @@ acc[relationship.to_sym] = { collection: is_collection, type: type, } + + acc end end def required_relationships if type == "item" - %i(item_type) + return %i(item_type) end (link_relationships.required || []).map(&:to_sym) end