module Roar::JSON::JSONAPI::ResourceCollection

Instance method API for JSON API Documents representing an array of Resources

@api private

Public Instance Methods

to_hash(options = {}) click to toggle source

@see Document#to_hash

Calls superclass method
# File lib/roar/json/json_api/resource_collection.rb, line 9
def to_hash(options = {})
  document = super(to_a: options, user_options: options[:user_options]) # [{data: {..}, data: {..}}]

  links = Renderer::Links.new.(document, options)
  meta  = render_meta(options)
  included = []
  document['data'].each do |single|
    included += single.delete('included') || []
  end

  HashUtils.store_if_any(document, 'included',
                         Fragment::Included.(included, options))
  HashUtils.store_if_any(document, 'links',    links)
  HashUtils.store_if_any(document, 'meta',     meta)

  document
end