Class: HttpClientGenerator::Plugs::ValidateResponse
- Inherits:
-
Object
- Object
- HttpClientGenerator::Plugs::ValidateResponse
- Defined in:
- lib/http_client_generator/plugs/validate_response.rb
Defined Under Namespace
Modules: SchemaBuilder
Instance Method Summary collapse
- #call(req) ⇒ Object
-
#initialize(schema_helper:, strict: false) ⇒ ValidateResponse
constructor
A new instance of ValidateResponse.
Constructor Details
#initialize(schema_helper:, strict: false) ⇒ ValidateResponse
Returns a new instance of ValidateResponse.
30 31 32 33 |
# File 'lib/http_client_generator/plugs/validate_response.rb', line 30 def initialize(schema_helper:, strict: false) @schema_helper = schema_helper @strict = strict end |
Instance Method Details
#call(req) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/http_client_generator/plugs/validate_response.rb', line 35 def call(req) schema_name = :"#{req.name}_#{req.verb}" return req unless @schema_helper.respond_to?(schema_name) req.response_body = @schema_helper.public_send(schema_name, req.response_body) .value_or { |e| req.(e.inspect) } req end |