Class: JSONAPIonify::Structure::Objects::Resource
- Inherits:
-
ResourceIdentifier
- Object
- Base
- ResourceIdentifier
- JSONAPIonify::Structure::Objects::Resource
- Defined in:
- lib/jsonapionify/structure/objects/resource.rb
Overview
ResourceObjects appear in a JSON API document to represent resources.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
#errors, #object, #parent, #warnings
Instance Method Summary collapse
-
#attribute_keys ⇒ Object
Note: This spec is agnostic about inflection rules, so the value of ‘type` can be either plural or singular.
- #relates_to?(other) ⇒ Boolean
- #relationship_keys ⇒ Object
Methods inherited from ResourceIdentifier
#duplicate_does_not_exist?, #duplicate_exists?, #eql?, #hash
Methods inherited from Base
#==, #===, #as_json, #compile, #compile!, #copy, define_order, from_hash, from_json, #initialize, #inspect, #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
Methods included from Callbacks
Constructor Details
This class inherits a constructor from JSONAPIonify::Structure::Objects::Base
Instance Method Details
#attribute_keys ⇒ Object
Note: This spec is agnostic about inflection rules, so the value of ‘type` can be either plural or singular. However, the same value should be used consistently throughout an implementation.
25 26 27 28 |
# File 'lib/jsonapionify/structure/objects/resource.rb', line 25 def attribute_keys return [] unless self[:attributes] self[:attributes].keys end |
#relates_to?(other) ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/jsonapionify/structure/objects/resource.rb', line 35 def relates_to?(other) relationships = self[:relationships] return false unless relationships relationships.any? do |_, resource_identifier| Array.wrap(resource_identifier[:data]).any? do |rel| rel[:id] == other[:id] && rel[:type] == other[:type] end end end |
#relationship_keys ⇒ Object
30 31 32 33 |
# File 'lib/jsonapionify/structure/objects/resource.rb', line 30 def relationship_keys return [] unless self[:relationships] self[:relationships].keys end |