Class: Interpol::ResponseSchemaValidator::Handler

Inherits:
Object
  • Object
show all
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

HandlerWithWarnings

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



31
32
33
# File 'lib/interpol/response_schema_validator.rb', line 31

def body
  @body
end

#configObject (readonly)

Returns the value of attribute config.



31
32
33
# File 'lib/interpol/response_schema_validator.rb', line 31

def config
  @config
end

#envObject (readonly)

Returns the value of attribute env.



31
32
33
# File 'lib/interpol/response_schema_validator.rb', line 31

def env
  @env
end

#headersObject (readonly)

Returns the value of attribute headers.



31
32
33
# File 'lib/interpol/response_schema_validator.rb', line 31

def headers
  @headers
end

#statusObject (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_bodyObject

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