Class: Roar::JSON::JSONAPI::Options::Include Private

Inherits:
Object
  • Object
show all
Defined in:
lib/roar/json/json_api/options.rb

Overview

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

Transforms field: and include:` options to their internal equivalents.

Constant Summary collapse

DEFAULT_INTERNAL_INCLUDES =

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

[:attributes, :relationships].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(options, mappings) ⇒ 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.



13
14
15
# File 'lib/roar/json/json_api/options.rb', line 13

def self.call(options, mappings)
  new.(options, mappings)
end

Instance Method Details

#call(options, mappings) ⇒ 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.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/roar/json/json_api/options.rb', line 17

def call(options, mappings)
  include, fields = *options.values_at(:include, :fields)
  return options if options[:_json_api_parsed] || !(include || fields)

  internal_options = {}
  rewrite_include_option!(internal_options, include,
                          mappings.fetch(:id, :id))
  rewrite_fields!(internal_options, fields,
                  mappings.fetch(:relationships, {}))

  options.reject { |key, _| [:include, :fields].include?(key) }
         .merge(internal_options)
end