Class: JsonApi::CollectionSerializer
- Inherits:
-
Serializer
- Object
- Serializer
- JsonApi::CollectionSerializer
- Defined in:
- lib/json_api_ruby/serializer.rb
Instance Attribute Summary
Attributes inherited from Serializer
Instance Method Summary collapse
Methods inherited from Serializer
#assemble_included_data, #find_included_resources, #initialize, #resource, #unique_identifiers!
Constructor Details
This class inherits a constructor from JsonApi::Serializer
Instance Method Details
#to_hash ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/json_api_ruby/serializer.rb', line 74 def to_hash serialized = {} included_resources = [] data_array = Array(@object).map do |object| object_resource = resource(object) included_resources += find_included_resources(object_resource) object_resource.to_hash end unique_identifiers!(included_resources) serialized['data'] = data_array serialized['included'] = assemble_included_data(included_resources) if included_resources.present? serialized['meta'] = @meta if @meta.present? serialized end |