Class: Cuprum::Rails::Responses::JsonResponse
- Inherits:
-
Object
- Object
- Cuprum::Rails::Responses::JsonResponse
- Defined in:
- lib/cuprum/rails/responses/json_response.rb
Overview
Encapsulates a JSON response that returns the given serialized data.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The JSON data to return.
-
#status ⇒ Integer
readonly
The HTTP status of the response.
Instance Method Summary collapse
-
#call(renderer) ⇒ Object
Calls the renderer’s #render method with the serialized data and status.
-
#initialize(data:, status: 200) ⇒ JsonResponse
constructor
A new instance of JsonResponse.
Constructor Details
#initialize(data:, status: 200) ⇒ JsonResponse
Returns a new instance of JsonResponse.
10 11 12 13 |
# File 'lib/cuprum/rails/responses/json_response.rb', line 10 def initialize(data:, status: 200) @data = data @status = status end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the JSON data to return.
16 17 18 |
# File 'lib/cuprum/rails/responses/json_response.rb', line 16 def data @data end |
#status ⇒ Integer (readonly)
Returns the HTTP status of the response.
19 20 21 |
# File 'lib/cuprum/rails/responses/json_response.rb', line 19 def status @status end |
Instance Method Details
#call(renderer) ⇒ Object
Calls the renderer’s #render method with the serialized data and status.
25 26 27 |
# File 'lib/cuprum/rails/responses/json_response.rb', line 25 def call(renderer) renderer.render(json: data, status: status) end |