Class: Jei::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/jei/document.rb,
lib/jei/document/builder.rb

Defined Under Namespace

Modules: Builder

Constant Summary collapse

VERSION =

Returns:

  • (String)
'1.0'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = {}) ⇒ Document

Returns a new instance of Document.



31
32
33
# File 'lib/jei/document.rb', line 31

def initialize(root = {})
  @root = root
end

Instance Attribute Details

#rootHash<Symbol, Object> (readonly) Also known as: to_h

Returns:

  • (Hash<Symbol, Object>)


7
8
9
# File 'lib/jei/document.rb', line 7

def root
  @root
end

Class Method Details

.build(resource, options = {}) ⇒ Document

Builds a document from a resource.

Parameters:

  • resource (Object)
  • options (Hash<Symbol, Object>) (defaults to: {})

Options Hash (options):

  • :errors (Array<Hash<Symbol, Object>>)

    override primary data with an array of error objects

  • :fields (Hash<String, String>)

    restrict resource attributes and relationships to a user-defined set of fields

  • :include (String)

    a list of relationship paths

  • :jsonapi (Boolean)

    add the top level JSON API object to the document

  • :links (Array<Link>)

    add links related to the primary data

  • :meta (Hash<Symbol, Object>)

    add top level meta information to the document

  • :serializer (Class)

    override the default serializer

Returns:



27
28
29
# File 'lib/jei/document.rb', line 27

def self.build(resource, options = {})
  Builder.build(resource, options)
end

Instance Method Details

#to_jsonString

Returns:

  • (String)


36
37
38
# File 'lib/jei/document.rb', line 36

def to_json
  to_h.to_json
end