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

Returns a new instance of ResourceBuilder.


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

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

  freeze
end

Instance Method Details

#build(objects, expose, klass = nil) ⇒ Object


11
12
13
14
15
16
17
18
19
20
# File 'lib/jsonapi/serializable/resource_builder.rb', line 11

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