Class: JSONAPI::Serializable::ResourceBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/serializable/resource_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(inferrer = nil) ⇒ ResourceBuilder

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.

Returns a new instance of ResourceBuilder.



5
6
7
8
9
10
# File 'lib/jsonapi/serializable/resource_builder.rb', line 5

def initialize(inferrer = nil)
  @inferrer = inferrer
  @lookup_cache = {}

  freeze
end

Instance Method Details

#build(objects, expose, klass = nil) ⇒ 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
16
17
18
19
20
21
22
# File 'lib/jsonapi/serializable/resource_builder.rb', line 13

def build(objects, expose, klass = nil)
  return objects if objects.nil? ||
                    Array(objects).first.respond_to?(:as_jsonapi)

  if objects.respond_to?(:to_ary)
    Array(objects).map { |obj| _build(obj, expose, klass) }
  else
    _build(objects, expose, klass)
  end
end