Sha256: 1296de09391cb237e3f0c8e5c5f295c9f40af0cf5e215ddbaa6346733cdc33c7

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

module Roar
  module JSON
    module JSONAPI
      # Instance method API for JSON API Documents representing an array of Resources
      #
      # @api private
      module ResourceCollection
        # @see Document#to_hash
        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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roar-jsonapi-0.0.3 lib/roar/json/json_api/resource_collection.rb