Module: Roar::JSON::JSONAPI::Options

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

Overview

:title, :author, :included],

:included=>{:include=>[:author], :author=>{:include=>[:email, :id]}}

Constant Summary collapse

Include =

TODO: make sure we don't change original params options.

->(options, decorator) do
  return options unless included = options[:include]
  included << :id # FIXME: changes original options.
  return options unless fields = options[:fields]

  internal_options = {}
  internal_options[:include] = [*included, :included]

  fields = options[:fields] || {}
  internal_options[:included] = {include: fields.keys}
  fields.each do |k,v|
    internal_options[:included][k] = {include: v+[:id]}
  end
   # pp internal_options
  options.merge(internal_options)
end