Module: Roar::JSON::JSONAPI::ResourceCollection Private

Defined in:
lib/roar/json/json_api/resource_collection.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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

Instance Method Summary collapse

Instance Method Details

#to_hash(options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Also:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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