Class: JSON::Api::Vanilla::Document
- Inherits:
-
Object
- Object
- JSON::Api::Vanilla::Document
- Defined in:
- lib/json-api-vanilla/parser.rb
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#data ⇒ Object+
readonly
The content of the JSON API data.
-
#errors ⇒ Array
readonly
A list of errors, if any, otherwise nil.
-
#keys ⇒ Hash
readonly
A map from objects to a Hash from their original field names (non-snake_case’d) to the corresponding object.
-
#links ⇒ Hash
readonly
A map from objects (obtained from .data) to their links, as a Hash.
-
#meta ⇒ Hash
readonly
A map from objects to their meta information (a Hash).
-
#rel_links ⇒ Hash
readonly
A map from objects’ relationships (obtained from .data) to the links defined in that relationship, as a Hash.
-
#superclass ⇒ Object
readonly
Returns the value of attribute superclass.
Instance Method Summary collapse
-
#find(type, id) ⇒ Object
Get a JSON API object.
-
#find_all(type) ⇒ Array<Object>
Get all JSON API objects of a given type.
-
#initialize(data, links: {}, rel_links: {}, meta: {}, keys: {}, objects: {}, errors: [], container: Module.new, superclass: Class.new) ⇒ Document
constructor
A new instance of Document.
Constructor Details
#initialize(data, links: {}, rel_links: {}, meta: {}, keys: {}, objects: {}, errors: [], container: Module.new, superclass: Class.new) ⇒ Document
Returns a new instance of Document.
201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/json-api-vanilla/parser.rb', line 201 def initialize(data, links: {}, rel_links: {}, meta: {}, keys: {}, objects: {}, errors: [], container: Module.new, superclass: Class.new) @data = data @links = links @rel_links = rel_links = @keys = keys @objects = objects @errors = errors @container = container @superclass = superclass end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
199 200 201 |
# File 'lib/json-api-vanilla/parser.rb', line 199 def container @container end |
#data ⇒ Object+ (readonly)
Returns the content of the JSON API data.
185 186 187 |
# File 'lib/json-api-vanilla/parser.rb', line 185 def data @data end |
#errors ⇒ Array (readonly)
Returns a list of errors, if any, otherwise nil.
195 196 197 |
# File 'lib/json-api-vanilla/parser.rb', line 195 def errors @errors end |
#keys ⇒ Hash (readonly)
Returns a map from objects to a Hash from their original field names (non-snake_case’d) to the corresponding object.
198 199 200 |
# File 'lib/json-api-vanilla/parser.rb', line 198 def keys @keys end |
#links ⇒ Hash (readonly)
Returns a map from objects (obtained from .data) to their links, as a Hash.
188 189 190 |
# File 'lib/json-api-vanilla/parser.rb', line 188 def links @links end |
#meta ⇒ Hash (readonly)
Returns a map from objects to their meta information (a Hash).
193 194 195 |
# File 'lib/json-api-vanilla/parser.rb', line 193 def end |
#rel_links ⇒ Hash (readonly)
Returns a map from objects’ relationships (obtained from .data) to the links defined in that relationship, as a Hash.
191 192 193 |
# File 'lib/json-api-vanilla/parser.rb', line 191 def rel_links @rel_links end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
200 201 202 |
# File 'lib/json-api-vanilla/parser.rb', line 200 def superclass @superclass end |
Instance Method Details
#find(type, id) ⇒ Object
Get a JSON API object.
220 221 222 |
# File 'lib/json-api-vanilla/parser.rb', line 220 def find(type, id) @objects[[type, id]] end |
#find_all(type) ⇒ Array<Object>
Get all JSON API objects of a given type.
228 229 230 |
# File 'lib/json-api-vanilla/parser.rb', line 228 def find_all(type) @objects.values.select { |obj| obj.type == type } end |