class JSONAPI::Document::Resource::Relationships

A JSONAPI resource's relationships

Public Class Methods

new(rels_obj_arr = []) click to toggle source

@param rels_obj_arr [Array<JSONAPI::Document::Resource::Relationships::Relationship]

The collection of relationships to initialize the collection with
Calls superclass method JSONAPI::NameValuePairCollection::new
# 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

Public Instance Methods

add(relationship) click to toggle source

Add a jsonapi member to the collection @param relationship [JSONAPI::Document::Resource::Relationships::Relationship] The member to add

Calls superclass method JSONAPI::NameValuePairCollection#add
# File lib/easy/jsonapi/document/resource/relationships.rb, line 21
def add(relationship)
  super(relationship, &:name)
end
to_h() click to toggle source

The jsonapi hash representation of a resource's relationships @return [Hash] A resource's relationships

# 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, :meta)
  end
  to_return
end