Class: JSONAPI::PathSegment::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi/path_segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relationship:, resource_klass: nil) ⇒ Relationship

Returns a new instance of Relationship.



27
28
29
30
# File 'lib/jsonapi/path_segment.rb', line 27

def initialize(relationship:, resource_klass: nil)
  @relationship = relationship
  @resource_klass = resource_klass
end

Instance Attribute Details

#relationshipObject (readonly)

Returns the value of attribute relationship.



25
26
27
# File 'lib/jsonapi/path_segment.rb', line 25

def relationship
  @relationship
end

#resource_klassObject (readonly)

Returns the value of attribute resource_klass.



25
26
27
# File 'lib/jsonapi/path_segment.rb', line 25

def resource_klass
  @resource_klass
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/jsonapi/path_segment.rb', line 32

def eql?(other)
  other.is_a?(JSONAPI::PathSegment::Relationship) && relationship == other.relationship && resource_klass == other.resource_klass
end

#hashObject



36
37
38
# File 'lib/jsonapi/path_segment.rb', line 36

def hash
  [relationship, resource_klass].hash
end

#path_specified_resource_klass?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/jsonapi/path_segment.rb', line 48

def path_specified_resource_klass?
  !@resource_klass.nil?
end

#to_sObject



40
41
42
# File 'lib/jsonapi/path_segment.rb', line 40

def to_s
  @resource_klass ? "#{relationship.parent_resource_klass._type}.#{relationship.name}##{resource_klass._type}" : "#{resource_klass._type}.#{relationship.name}"
end