Class: Subjoin::Document
- Inherits:
-
Object
- Object
- Subjoin::Document
- Defined in:
- lib/subjoin/document.rb
Overview
A JSON-API top level document
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The document’s primary data.
-
#included ⇒ Object
readonly
Resources included in a compound document“.
-
#jsonapi ⇒ Object
readonly
JSON-API version information.
Attributes included from Linkable
Attributes included from Metable
Instance Method Summary collapse
-
#has_data? ⇒ Boolean
True if there is primary data.
-
#has_included? ⇒ Boolean
True if there are included resources.
-
#has_jsonapi? ⇒ Boolean
True if there is version information.
-
#initialize(*args) ⇒ Document
constructor
Create a document.
Methods included from Linkable
Methods included from Metable
Constructor Details
#initialize(*args) ⇒ Document
Create a document. Parameters can take several forms:
-
A URI object: Document will be created from the URI
-
A Hash: The Hash is assumed to be a parsed JSON response and the Document will be created from that
-
One string: Assumed to be a JSON-API object type. An attempt will be made to map this type to a class that inherits from InheritableResource and to load the create the Document from a URL provided by that class. There is also the assumption that this URL returns all objects of that type.
-
Two strings: Assumed to be a JSON-API object type and id. The same mapping is attempted as before, and the second parameter is added to the URL
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/subjoin/document.rb', line 30 def initialize(*args) if args.count < 1 raise ArgumentError.new end contents = load_by_type(args[0], args[1..-1]) = (contents['meta']) @links = load_links(contents['links']) @included = load_included(contents) @data = load_data(contents) @jsonapi = load_jsonapi(contents) end |
Instance Attribute Details
#data ⇒ Object (readonly)
The document’s primary data
8 9 10 |
# File 'lib/subjoin/document.rb', line 8 def data @data end |
#included ⇒ Object (readonly)
Resources included in a compound document“
11 12 13 |
# File 'lib/subjoin/document.rb', line 11 def included @included end |
#jsonapi ⇒ Object (readonly)
JSON-API version information
14 15 16 |
# File 'lib/subjoin/document.rb', line 14 def jsonapi @jsonapi end |
Instance Method Details
#has_data? ⇒ Boolean
Returns true if there is primary data.
45 46 47 |
# File 'lib/subjoin/document.rb', line 45 def has_data? return ! @data.nil? end |
#has_included? ⇒ Boolean
Returns true if there are included resources.
50 51 52 |
# File 'lib/subjoin/document.rb', line 50 def has_included? return ! @included.nil? end |
#has_jsonapi? ⇒ Boolean
Returns true if there is version information.
55 56 57 |
# File 'lib/subjoin/document.rb', line 55 def has_jsonapi? return ! @jsonapi.nil? end |