Class: JsonapiCompliable::Util::RenderOptions Private

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi_compliable/util/render_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.

Generate the options we end up passing to jsonapi-rb}

Class Method Summary collapse

Class Method Details

.generate(object, query_hash, overrides = {}) ⇒ 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.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jsonapi_compliable/util/render_options.rb', line 6

def self.generate(object, query_hash, overrides = {})
  resolved = object.respond_to?(:resolve) ? object.resolve : object

  options            = {}
  options[:include]  = query_hash[:include]
  options[:jsonapi]  = resolved
  options[:fields]   = query_hash[:fields]
  options.merge!(overrides)
  options[:meta]   ||= {}
  options[:expose] ||= {}
  options[:expose][:extra_fields] = query_hash[:extra_fields]

  if object.respond_to?(:resolve_stats)
    stats = object.resolve_stats
    options[:meta][:stats] = stats unless stats.empty?
  end

  options
end