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.
233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/json-api-vanilla/parser.rb', line 233 def initialize(data, links: {}, rel_links: {}, meta: {}, keys: {}, objects: {}, errors: [], container: Module.new, superclass: Class.new) @data = data @links = links @rel_links = rel_links @meta = @keys = keys @objects = objects @errors = errors @container = container @superclass = superclass end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
231 232 233 |
# File 'lib/json-api-vanilla/parser.rb', line 231 def container @container end |
#data ⇒ Object+ (readonly)
Returns the content of the JSON API data.
217 218 219 |
# File 'lib/json-api-vanilla/parser.rb', line 217 def data @data end |
#errors ⇒ Array (readonly)
Returns a list of errors, if any, otherwise nil.
227 228 229 |
# File 'lib/json-api-vanilla/parser.rb', line 227 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.
230 231 232 |
# File 'lib/json-api-vanilla/parser.rb', line 230 def keys @keys end |
#links ⇒ Hash (readonly)
Returns a map from objects (obtained from .data) to their links, as a Hash.
220 221 222 |
# File 'lib/json-api-vanilla/parser.rb', line 220 def links @links end |
#meta ⇒ Hash (readonly)
Returns a map from objects to their meta information (a Hash).
225 226 227 |
# File 'lib/json-api-vanilla/parser.rb', line 225 def @meta end |
#rel_links ⇒ Hash (readonly)
Returns a map from objects’ relationships (obtained from .data) to the links defined in that relationship, as a Hash.
223 224 225 |
# File 'lib/json-api-vanilla/parser.rb', line 223 def rel_links @rel_links end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
232 233 234 |
# File 'lib/json-api-vanilla/parser.rb', line 232 def superclass @superclass end |
Instance Method Details
#find(type, id) ⇒ Object
Get a JSON API object.
252 253 254 |
# File 'lib/json-api-vanilla/parser.rb', line 252 def find(type, id) @objects[[type, id]] end |
#find_all(type) ⇒ Array<Object>
Get all JSON API objects of a given type.
260 261 262 |
# File 'lib/json-api-vanilla/parser.rb', line 260 def find_all(type) @objects.values.select { |obj| obj.type == type } end |