Class: FunWithJsonApi::SchemaValidator
- Inherits:
-
Object
- Object
- FunWithJsonApi::SchemaValidator
- Defined in:
- lib/fun_with_json_api/schema_validator.rb
Instance Attribute Summary collapse
-
#deserializer ⇒ Object
readonly
Returns the value of attribute deserializer.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
- #check ⇒ Object
- #document_id ⇒ Object
- #document_type ⇒ Object
-
#initialize(document, deserializer, resource) ⇒ SchemaValidator
constructor
A new instance of SchemaValidator.
- #resource_id ⇒ Object
- #resource_type ⇒ Object
Constructor Details
#initialize(document, deserializer, resource) ⇒ SchemaValidator
Returns a new instance of SchemaValidator.
15 16 17 18 19 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 15 def initialize(document, deserializer, resource) @document = FunWithJsonApi.sanitize_document(document) @deserializer = deserializer @resource = resource end |
Instance Attribute Details
#deserializer ⇒ Object (readonly)
Returns the value of attribute deserializer.
12 13 14 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 12 def deserializer @deserializer end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
11 12 13 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 11 def document @document end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
13 14 15 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 13 def resource @resource end |
Class Method Details
.check(document, deserializer, resource) ⇒ Object
5 6 7 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 5 def self.check(document, deserializer, resource) new(document, deserializer, resource).check end |
Instance Method Details
#check ⇒ Object
21 22 23 24 25 26 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 21 def check FunWithJsonApi::SchemaValidators::CheckDocumentTypeMatchesResource.call(self) FunWithJsonApi::SchemaValidators::CheckDocumentIdMatchesResource.call(self) FunWithJsonApi::SchemaValidators::CheckAttributeNames.call(document, deserializer) FunWithJsonApi::SchemaValidators::CheckRelationships.call(document, deserializer) end |
#document_id ⇒ Object
28 29 30 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 28 def document_id @document_id ||= document['data']['id'] end |
#document_type ⇒ Object
32 33 34 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 32 def document_type @document_type ||= document['data']['type'] end |
#resource_id ⇒ Object
36 37 38 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 36 def resource_id @resource_id ||= resource.send(deserializer.id_param).to_s end |
#resource_type ⇒ Object
40 41 42 |
# File 'lib/fun_with_json_api/schema_validator.rb', line 40 def resource_type @resource_type ||= deserializer.type end |