Class: OpenAPIRest::RestRenderer
- Inherits:
-
Object
- Object
- OpenAPIRest::RestRenderer
- Defined in:
- lib/openapi_rest/rest_renderer.rb
Overview
Rest Response Renderer
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(args) ⇒ RestRenderer
constructor
A new instance of RestRenderer.
- #render ⇒ Object
Constructor Details
#initialize(args) ⇒ RestRenderer
Returns a new instance of RestRenderer.
9 10 11 12 |
# File 'lib/openapi_rest/rest_renderer.rb', line 9 def initialize(args) @controller = args[:controller] @response = args[:response] end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
6 7 8 |
# File 'lib/openapi_rest/rest_renderer.rb', line 6 def controller @controller end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/openapi_rest/rest_renderer.rb', line 7 def response @response end |
Instance Method Details
#render ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openapi_rest/rest_renderer.rb', line 14 def render unless response.is_a?(OpenAPIRest::QueryResponse) controller.render(response) return end return controller.render(error_response) if response.errors? method = controller.request.request_method_symbol return controller.render(nothing: true, status: 204) if [:delete, :patch, :put].include?(method) if method == :post path = "#{controller.openapi_path[:namespace]}#{response.resource}_path" controller.render(json: to_json_response, status: 201, location: controller.send(path, response.results)) return end controller.render(json: to_json_response) end |