Class: JSONAPIonify::Structure::Objects::ResourceIdentifier

Inherits:
Base
  • Object
show all
Defined in:
lib/jsonapionify/structure/objects/resource_identifier.rb

Direct Known Subclasses

Resource

Instance Attribute Summary

Attributes inherited from Base

#errors, #object, #parent, #warnings

Instance Method Summary collapse

Methods inherited from Base

#===, #as_json, #compile, #compile!, #copy, define_order, from_hash, from_json, #initialize, #pretty_json, #signature, #to_h, #to_json, #validate

Methods included from Helpers::ObjectDefaults

#[], #[]=

Methods included from Helpers::Validations

#allowed_type_map, #permitted_key?, #permitted_keys, #permitted_type_for?, #permitted_types_for, #required_key?, #required_keys

Methods included from Helpers::ObjectSetters

#[], #[]=

Methods included from Helpers::InheritsOrigin

#client?, #origin, #server?

Methods included from Callbacks

#run_callbacks

Constructor Details

This class inherits a constructor from JSONAPIonify::Structure::Objects::Base

Instance Method Details

#==(other) ⇒ Object



29
30
31
# File 'lib/jsonapionify/structure/objects/resource_identifier.rb', line 29

def ==(other)
  same_as? other
end

#duplicate_does_not_exist?Boolean

Returns:



33
34
35
# File 'lib/jsonapionify/structure/objects/resource_identifier.rb', line 33

def duplicate_does_not_exist?
  !duplicate_exists?
end

#duplicate_exists?Boolean

Returns:



23
24
25
26
27
# File 'lib/jsonapionify/structure/objects/resource_identifier.rb', line 23

def duplicate_exists?
  return false unless parent.is_a?(Array)
  peers = parent - [self]
  !!peers.index(self)
end

#same_as?(other) ⇒ Boolean

Returns:



37
38
39
40
41
42
43
44
# File 'lib/jsonapionify/structure/objects/resource_identifier.rb', line 37

def same_as?(other)
  return false unless other.is_a? ResourceIdentifier
  other_type, other_id = other.values_at :type, :id
  local_type, local_id = values_at :type, :id
  other_type == local_type &&
    !(other_id || local_id).nil? &&
    other_id == local_id
end