Class: Interpol::ResponseSchemaValidator::Handler
- Inherits:
-
Object
- Object
- Interpol::ResponseSchemaValidator::Handler
- Defined in:
- lib/interpol/response_schema_validator.rb
Overview
Private: handles a responses and validates it. Validation errors will result in an error.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#extracted_body ⇒ Object
The only interface we can count on from the body is that it implements #each.
-
#initialize(status, headers, body, env, config) ⇒ Handler
constructor
A new instance of Handler.
- #validate! ⇒ Object
Constructor Details
#initialize(status, headers, body, env, config) ⇒ Handler
Returns a new instance of Handler.
33 34 35 |
# File 'lib/interpol/response_schema_validator.rb', line 33 def initialize(status, headers, body, env, config) @status, @headers, @body, @env, @config = status, headers, body, env, config end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
31 32 33 |
# File 'lib/interpol/response_schema_validator.rb', line 31 def body @body end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
31 32 33 |
# File 'lib/interpol/response_schema_validator.rb', line 31 def config @config end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
31 32 33 |
# File 'lib/interpol/response_schema_validator.rb', line 31 def env @env end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
31 32 33 |
# File 'lib/interpol/response_schema_validator.rb', line 31 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
31 32 33 |
# File 'lib/interpol/response_schema_validator.rb', line 31 def status @status end |
Instance Method Details
#extracted_body ⇒ Object
The only interface we can count on from the body is that it implements #each. It may not be re-windable. To preserve this interface while reading the whole thing, we need to extract it into our own array.
50 51 52 53 54 55 |
# File 'lib/interpol/response_schema_validator.rb', line 50 def extracted_body @extracted_body ||= [].tap do |extracted_body| body.each { |str| extracted_body << str } body.close if body.respond_to?(:close) end end |
#validate! ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/interpol/response_schema_validator.rb', line 37 def validate! unless validator == Interpol::DefinitionFinder::NoDefinitionFound return validator.validate_data!(data) end raise NoEndpointDefinitionFoundError, "No endpoint definition could be found for: #{request_method} '#{path}'" end |