Class: JSONAPI::Document::Resource::Relationships
- Inherits:
-
NameValuePairCollection
- Object
- Collection
- NameValuePairCollection
- JSONAPI::Document::Resource::Relationships
- Defined in:
- lib/easy/jsonapi/document/resource/relationships.rb,
lib/easy/jsonapi/document/resource/relationships/relationship.rb
Overview
A JSONAPI resource’s relationships
Defined Under Namespace
Classes: Relationship
Instance Method Summary collapse
-
#add(relationship) ⇒ Object
Add a jsonapi member to the collection.
-
#initialize(rels_obj_arr = []) ⇒ Relationships
constructor
A new instance of Relationships.
-
#to_h ⇒ Hash
The jsonapi hash representation of a resource’s relationships.
Methods inherited from NameValuePairCollection
Methods inherited from Collection
#[], #[]=, #each, #empty?, #get, #include?, #insert, #keys, #remove, #set, #size, #to_s
Constructor Details
#initialize(rels_obj_arr = []) ⇒ Relationships
Returns a new instance of Relationships.
15 16 17 |
# File 'lib/easy/jsonapi/document/resource/relationships.rb', line 15 def initialize(rels_obj_arr = []) super(rels_obj_arr, item_type: JSONAPI::Document::Resource::Relationships::Relationship) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class JSONAPI::NameValuePairCollection
Instance Method Details
#add(relationship) ⇒ Object
Add a jsonapi member to the collection
21 22 23 |
# File 'lib/easy/jsonapi/document/resource/relationships.rb', line 21 def add(relationship) super(relationship, &:name) end |
#to_h ⇒ Hash
The jsonapi hash representation of a resource’s relationships
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/easy/jsonapi/document/resource/relationships.rb', line 27 def to_h to_return = {} each do |rel| to_return[rel.name.to_sym] = {} JSONAPI::Utility.to_h_member(to_return[rel.name.to_sym], rel.links, :links) JSONAPI::Utility.to_h_member(to_return[rel.name.to_sym], rel.data, :data) JSONAPI::Utility.to_h_member(to_return[rel.name.to_sym], rel., :meta) end to_return end |