class Cuprum::Rails::Responses::JsonResponse

Encapsulates a JSON response that returns the given serialized data.

Attributes

data[R]

@return [Object] the JSON data to return.

status[R]

@return [Integer] the HTTP status of the response.

Public Class Methods

new(data:, status: 200) click to toggle source

@param data [Object] The JSON data to return. @param status [Integer] The HTTP status of the response.

# File lib/cuprum/rails/responses/json_response.rb, line 10
def initialize(data:, status: 200)
  @data   = data
  @status = status
end

Public Instance Methods

call(renderer) click to toggle source

Calls the renderer’s render method with the serialized data and status.

@param renderer [#render] The context for executing the response, such as

a Rails controller.
# File lib/cuprum/rails/responses/json_response.rb, line 25
def call(renderer)
  renderer.render(json: data, status: status)
end