Class: JSONAPI::Document
- Inherits:
-
Object
- Object
- JSONAPI::Document
- Defined in:
- lib/easy/jsonapi/document.rb,
lib/easy/jsonapi/document/meta.rb,
lib/easy/jsonapi/document/error.rb,
lib/easy/jsonapi/document/links.rb,
lib/easy/jsonapi/document/jsonapi.rb,
lib/easy/jsonapi/document/resource.rb,
lib/easy/jsonapi/document/links/link.rb,
lib/easy/jsonapi/document/resource_id.rb,
lib/easy/jsonapi/document/meta/meta_member.rb,
lib/easy/jsonapi/document/error/error_member.rb,
lib/easy/jsonapi/document/resource/attributes.rb,
lib/easy/jsonapi/document/jsonapi/jsonapi_member.rb,
lib/easy/jsonapi/document/resource/relationships.rb,
lib/easy/jsonapi/document/resource/attributes/attribute.rb,
lib/easy/jsonapi/document/resource/relationships/relationship.rb
Overview
Contains all objects relating to a JSONAPI Document
Defined Under Namespace
Classes: Error, Jsonapi, Links, Meta, Resource, ResourceId
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#included ⇒ Object
readonly
Returns the value of attribute included.
-
#jsonapi ⇒ Object
readonly
Returns the value of attribute jsonapi.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Instance Method Summary collapse
-
#initialize(document = {}) ⇒ Document
constructor
A new instance of Document.
-
#to_h ⇒ Object
Represent as a hash mimicing the JSONAPI format.
-
#to_s ⇒ Object
Represent as a string mimicing the JSONAPI format.
-
#validate ⇒ Object
Check if the document is JSONAPI compliant.
Constructor Details
#initialize(document = {}) ⇒ Document
Returns a new instance of Document.
31 32 33 34 35 36 37 38 39 |
# File 'lib/easy/jsonapi/document.rb', line 31 def initialize(document = {}) raise 'JSONAPI::Document parameter must be a Hash' unless document.is_a? Hash @data = document[:data] @meta = document[:meta] @links = document[:links] # software generated? @included = document[:included] @errors = document[:errors] @jsonapi = document[:jsonapi] # online documentation end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
19 20 21 |
# File 'lib/easy/jsonapi/document.rb', line 19 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
19 20 21 |
# File 'lib/easy/jsonapi/document.rb', line 19 def errors @errors end |
#included ⇒ Object (readonly)
Returns the value of attribute included.
19 20 21 |
# File 'lib/easy/jsonapi/document.rb', line 19 def included @included end |
#jsonapi ⇒ Object (readonly)
Returns the value of attribute jsonapi.
19 20 21 |
# File 'lib/easy/jsonapi/document.rb', line 19 def jsonapi @jsonapi end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
19 20 21 |
# File 'lib/easy/jsonapi/document.rb', line 19 def links @links end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
19 20 21 |
# File 'lib/easy/jsonapi/document.rb', line 19 def @meta end |
Instance Method Details
#to_h ⇒ Object
Represent as a hash mimicing the JSONAPI format
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/easy/jsonapi/document.rb', line 54 def to_h to_return = {} JSONAPI::Utility.to_h_member(to_return, @data, :data) JSONAPI::Utility.to_h_member(to_return, @meta, :meta) JSONAPI::Utility.to_h_member(to_return, @links, :links) JSONAPI::Utility.to_h_member(to_return, @included, :included) JSONAPI::Utility.to_h_member(to_return, @errors, :errors) JSONAPI::Utility.to_h_member(to_return, @jsonapi, :jsonapi) to_return end |
#to_s ⇒ Object
Represent as a string mimicing the JSONAPI format
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/easy/jsonapi/document.rb', line 42 def to_s '{ ' \ "#{JSONAPI::Utility.member_to_s('data', @data, first_member: true)}" \ "#{JSONAPI::Utility.member_to_s('meta', @meta)}" \ "#{JSONAPI::Utility.member_to_s('links', @links)}" \ "#{JSONAPI::Utility.member_to_s('included', @included)}" \ "#{JSONAPI::Utility.member_to_s('errors', @errors)}" \ "#{JSONAPI::Utility.member_to_s('jsonapi', @jsonapi)}" \ ' }' end |
#validate ⇒ Object
Check if the document is JSONAPI compliant
67 68 69 |
# File 'lib/easy/jsonapi/document.rb', line 67 def validate JSONAPI::Exceptions::DocumentExceptions.check_compliance(to_h) end |