class JSONAPI::Store
Basic in-memory store implementation compliant with JSON API
Constants
- VERSION
Public Instance Methods
<<(entity)
click to toggle source
@param [JSONAPI::Store::Entity] entity @return [JSONAPI::Store] store itself
# File lib/jsonapi/store.rb, line 13 def <<(entity) entity = Entity.new(entity) entities << entity entity.relationships.each do |_name, data| Array(data).each do |relationship| relationship = Entity.new(relationship) self << relationship unless self[relationship.identifier] end end self end
all(type)
click to toggle source
@param [#to_s] type @return [<JSONAPI::Store::Entity>]
# File lib/jsonapi/store.rb, line 41 def all(type) type = type.to_s select { |entity| entity.type == type } end
each(&block)
click to toggle source
@overload each(&block)
@return [<JSONAPI::Store::Entity>]
@overload each
@return [Enumerator<JSONAPI::Store::Entity>]
# File lib/jsonapi/store.rb, line 65 def each(&block) entities.each(&block) end
entities()
click to toggle source
@return [<JSONAPI::Store::Entity>]
# File lib/jsonapi/store.rb, line 52 def entities @entities ||= [] end
fetch(*args)
click to toggle source
@overload fetch(identifier)
@param [#to_s] identifier @return [JSONAPI::Store::Entity?]
@overload fetch(type, id)
@param [#to_s] type @param [#to_s] id @return [JSONAPI::Store::Entity?]
# File lib/jsonapi/store.rb, line 32 def fetch(*args) identifier = args.size == 2 ? args.join('/') : args.first.to_s detect { |entity| entity.identifier == identifier } end
Also aliased as: []
size()
click to toggle source
@return [Integer]
# File lib/jsonapi/store.rb, line 57 def size entities.size end
types()
click to toggle source
@return [<String>]
# File lib/jsonapi/store.rb, line 47 def types entities.map(&:type).uniq end