Class: SimpleJsonApi::Builder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simple_json_api/builder.rb

Overview

The Builder to walk the hierarchy and construct the JSON

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, wrapper, serializer, fields, include, page) ⇒ Builder

TODO: sort: nil



22
23
24
25
26
27
28
29
# File 'lib/simple_json_api/builder.rb', line 22

def initialize(object, wrapper, serializer, fields, include, page)
  @object = object
  @wrapper = wrapper
  @field_list = FieldList.new(fields, serializer)
  @include = IncludeList.new(include).parse
  @page = page
  @serializer = SerializerFactory.create(object, serializer, self)
end

Instance Attribute Details

#field_listObject (readonly)

Returns the value of attribute field_list.



14
15
16
# File 'lib/simple_json_api/builder.rb', line 14

def field_list
  @field_list
end

#includeObject (readonly)

Returns the value of attribute include.



15
16
17
# File 'lib/simple_json_api/builder.rb', line 15

def include
  @include
end

#objectObject (readonly)

Returns the value of attribute object.



16
17
18
# File 'lib/simple_json_api/builder.rb', line 16

def object
  @object
end

#serializerObject (readonly)

Returns the value of attribute serializer.



17
18
19
# File 'lib/simple_json_api/builder.rb', line 17

def serializer
  @serializer
end

#wrapperObject (readonly)

Returns the value of attribute wrapper.



13
14
15
# File 'lib/simple_json_api/builder.rb', line 13

def wrapper
  @wrapper
end

Instance Method Details

#as_json(options = nil) ⇒ Object



31
32
33
34
35
36
# File 'lib/simple_json_api/builder.rb', line 31

def as_json(options = nil)
  root_node = ApiNode.new(
    serializer._root_name, serializer, include.include_hash
  ).load
  wrapper.new(root_node, @page).as_json(options)
end