Class: Committee::Middleware::ResponseValidation
- Defined in:
- lib/committee/middleware/response_validation.rb
Instance Attribute Summary collapse
-
#validate_success_only ⇒ Object
readonly
Returns the value of attribute validate_success_only.
Class Method Summary collapse
Instance Method Summary collapse
- #handle(request) ⇒ Object
-
#initialize(app, options = {}) ⇒ ResponseValidation
constructor
A new instance of ResponseValidation.
Methods inherited from Base
Constructor Details
#initialize(app, options = {}) ⇒ ResponseValidation
Returns a new instance of ResponseValidation.
8 9 10 11 12 |
# File 'lib/committee/middleware/response_validation.rb', line 8 def initialize(app, = {}) super @strict = [:strict] @validate_success_only = @schema.validator_option.validate_success_only end |
Instance Attribute Details
#validate_success_only ⇒ Object (readonly)
Returns the value of attribute validate_success_only.
6 7 8 |
# File 'lib/committee/middleware/response_validation.rb', line 6 def validate_success_only @validate_success_only end |
Class Method Details
.validate?(status, validate_success_only) ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/committee/middleware/response_validation.rb', line 37 def validate?(status, validate_success_only) case status when 204 false when 200..299 true when 304 false else !validate_success_only end end |
Instance Method Details
#handle(request) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/committee/middleware/response_validation.rb', line 14 def handle(request) status, headers, response = @app.call(request.env) begin v = build_schema_validator(request) v.response_validate(status, headers, response, @strict) if v.link_exist? && self.class.validate?(status, validate_success_only) rescue Committee::InvalidResponse handle_exception($!, request.env) raise if @raise return @error_class.new(500, :invalid_response, $!.).render unless @ignore_error rescue JSON::ParserError handle_exception($!, request.env) raise Committee::InvalidResponse if @raise return @error_class.new(500, :invalid_response, "Response wasn't valid JSON.").render unless @ignore_error end [status, headers, response] end |