class JSON::Api::Vanilla::Document
Attributes
container[R]
data[R]
@return [Object, Array<Object>] the content of the JSON API data.
errors[R]
@return [Array] a list of errors, if any, otherwise nil.
keys[R]
@return [Hash] a map from objects to a Hash from their original field
names (non-snake_case'd) to the corresponding object.
links[R]
@return [Hash] a map from objects (obtained from .data) to their links,
as a Hash.
meta[R]
@return [Hash] a map from objects to their meta information (a Hash).
rel_links[R]
@return [Hash] a map from objects' relationships (obtained from .data)
to the links defined in that relationship, as a Hash.
superclass[R]
Public Class Methods
new(data, links: {}, rel_links: {}, meta: {}, keys: {}, objects: {}, errors: [], container: Module.new, superclass: Class.new)
click to toggle source
# File lib/json-api-vanilla/parser.rb, line 219 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 = meta @keys = keys @objects = objects @errors = errors @container = container @superclass = superclass end
Public Instance Methods
find(type, id)
click to toggle source
Get a JSON API object.
@param type [String] the type of the object we want returned. @param id [String] its id. @return [Object] the object with that type and id.
# File lib/json-api-vanilla/parser.rb, line 238 def find(type, id) @objects[[type, id]] end
find_all(type)
click to toggle source
Get all JSON API objects of a given type.
@param type [String] the type of the objects we want returned. @return [Array<Object>] the list of objects with that type.
# File lib/json-api-vanilla/parser.rb, line 246 def find_all(type) @objects.values.select { |obj| obj.type == type } end