Class: FunWithJsonApi::SchemaValidators::CheckRelationshipNames
- Inherits:
-
Object
- Object
- FunWithJsonApi::SchemaValidators::CheckRelationshipNames
- Defined in:
- lib/fun_with_json_api/schema_validators/check_relationship_names.rb
Overview
Ensures all provided relationship names are known
Instance Attribute Summary collapse
-
#deserializer ⇒ Object
readonly
Returns the value of attribute deserializer.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#relationship_keys ⇒ Object
readonly
Returns the value of attribute relationship_keys.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(document, deserializer, relationship_keys) ⇒ CheckRelationshipNames
constructor
A new instance of CheckRelationshipNames.
Constructor Details
#initialize(document, deserializer, relationship_keys) ⇒ CheckRelationshipNames
Returns a new instance of CheckRelationshipNames.
13 14 15 16 17 |
# File 'lib/fun_with_json_api/schema_validators/check_relationship_names.rb', line 13 def initialize(document, deserializer, relationship_keys) @document = document @deserializer = deserializer @relationship_keys = relationship_keys end |
Instance Attribute Details
#deserializer ⇒ Object (readonly)
Returns the value of attribute deserializer.
10 11 12 |
# File 'lib/fun_with_json_api/schema_validators/check_relationship_names.rb', line 10 def deserializer @deserializer end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
9 10 11 |
# File 'lib/fun_with_json_api/schema_validators/check_relationship_names.rb', line 9 def document @document end |
#relationship_keys ⇒ Object (readonly)
Returns the value of attribute relationship_keys.
11 12 13 |
# File 'lib/fun_with_json_api/schema_validators/check_relationship_names.rb', line 11 def relationship_keys @relationship_keys end |
Class Method Details
.call ⇒ Object
5 6 7 |
# File 'lib/fun_with_json_api/schema_validators/check_relationship_names.rb', line 5 def self.call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fun_with_json_api/schema_validators/check_relationship_names.rb', line 19 def call unknown = relationship_keys.reject { |rel| resource_relationships.include?(rel) } return if unknown.empty? = unknown.select do |relationship| known_relationships.include?(relationship) end if .any? raise () else raise build_unknown_relationship_error(unknown) end end |