Module: Hypermodel
- Defined in:
- lib/hypermodel.rb,
lib/hypermodel/version.rb,
lib/hypermodel/resource.rb,
lib/hypermodel/responder.rb,
lib/hypermodel/collection.rb,
lib/hypermodel/serializer.rb,
lib/hypermodel/empty_collection.rb,
lib/hypermodel/traverse_ancestors.rb,
lib/hypermodel/serializers/mongoid.rb
Overview
Public: A Hypermodel is a representation of a resource in a JSON-HAL format. To learn more about JSON HAL see stateless.co/hal_specification.html
Defined Under Namespace
Modules: Serializers Classes: Collection, EmptyCollection, Resource, Responder, Serializer
Constant Summary collapse
- VERSION =
"0.2.1"
- TraverseAncestors =
Public: Recursive function that traverses a record’s referential hierarchy upwards.
Returns a flattened Array with the hierarchy of records.
lambda do |record| serializer = Serializers::Mongoid.new(record) parent_name, parent_resource = ( serializer..first || serializer.resources.first ) # If we have a parent if parent_resource # Recurse over parent hierarchies [TraverseAncestors[parent_resource], record].flatten else # Final case, we are the topmost parent: return ourselves [record] end end