Class: JsonApi::Resources::RelationshipMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/json_api_ruby/resources/relationships.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ RelationshipMeta

Returns a new instance of RelationshipMeta.



15
16
17
18
# File 'lib/json_api_ruby/resources/relationships.rb', line 15

def initialize(name, options)
  @name = name.to_s
  @cardinality = options.fetch(:cardinality)
end

Instance Attribute Details

#cardinalityObject (readonly)

Returns the value of attribute cardinality.



13
14
15
# File 'lib/json_api_ruby/resources/relationships.rb', line 13

def cardinality
  @cardinality
end

#nameObject (readonly)

The name of this relationship.

This name comes from the resource object that defines the
relationship. Example:
  class ArticleResource < JsonApi::Resource
    has_one :author # this is the name of this relationship
  end


11
12
13
# File 'lib/json_api_ruby/resources/relationships.rb', line 11

def name
  @name
end

Instance Method Details

#build_resources(options) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/json_api_ruby/resources/relationships.rb', line 20

def build_resources(options)
  if cardinality == :one
    relationship = ToOneRelationship.new(name, options)
  else
    relationship = ToManyRelationship.new(name, options)
  end
  relationship.build_resources(options)
  relationship
end