Module: JSONAPI::Utils::Response::Renders
- Included in:
 - JSONAPI::Utils::Response
 
- Defined in:
 - lib/jsonapi/utils/response/renders.rb
 
Instance Method Summary collapse
- 
  
    
      #jsonapi_render(json:, status: nil, options: {})  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Helper method to render JSON API-compliant responses.
 - 
  
    
      #jsonapi_render_bad_request  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Helper method to render HTTP 400 Bad Request.
 - 
  
    
      #jsonapi_render_errors(error = nil, json: nil, status: nil)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Helper method to render JSON API-compliant error responses.
 - 
  
    
      #jsonapi_render_internal_server_error  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Helper method to render HTTP 500 Interval Server Error.
 - 
  
    
      #jsonapi_render_not_found(exception)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Helper method to render HTTP 404 Bad Request.
 - 
  
    
      #jsonapi_render_not_found_with_null  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Helper method to render HTTP 404 Bad Request with null “data”.
 
Instance Method Details
#jsonapi_render(json:, status: nil, options: {}) ⇒ String
Helper method to render JSON API-compliant responses.
      33 34 35 36 37 38 39 40  | 
    
      # File 'lib/jsonapi/utils/response/renders.rb', line 33 def jsonapi_render(json:, status: nil, options: {}) body = jsonapi_format(json, ) render json: body, status: (status || @_response_document.status) rescue => e handle_exceptions(e) # http://bit.ly/2sEEGTN ensure correct_media_type end  | 
  
#jsonapi_render_bad_request ⇒ Object
Helper method to render HTTP 400 Bad Request.
      76 77 78  | 
    
      # File 'lib/jsonapi/utils/response/renders.rb', line 76 def jsonapi_render_bad_request jsonapi_render_errors(::JSONAPI::Utils::Exceptions::BadRequest.new) end  | 
  
#jsonapi_render_errors(error = nil, json: nil, status: nil) ⇒ String
Helper method to render JSON API-compliant error responses.
      58 59 60 61 62 63 64  | 
    
      # File 'lib/jsonapi/utils/response/renders.rb', line 58 def jsonapi_render_errors(error = nil, json: nil, status: nil) body = jsonapi_format_errors(error || json) status = status || body.try(:first).try(:[], :status) || :bad_request render json: { errors: body }, status: status ensure correct_media_type end  | 
  
#jsonapi_render_internal_server_error ⇒ Object
Helper method to render HTTP 500 Interval Server Error.
      69 70 71  | 
    
      # File 'lib/jsonapi/utils/response/renders.rb', line 69 def jsonapi_render_internal_server_error jsonapi_render_errors(::JSONAPI::Utils::Exceptions::InternalServerError.new) end  | 
  
#jsonapi_render_not_found(exception) ⇒ Object
Helper method to render HTTP 404 Bad Request.
      83 84 85 86  | 
    
      # File 'lib/jsonapi/utils/response/renders.rb', line 83 def jsonapi_render_not_found(exception) id = exception. =~ /=([\w-]+)/ && $1 || '(no identifier)' jsonapi_render_errors(JSONAPI::Exceptions::RecordNotFound.new(id)) end  | 
  
#jsonapi_render_not_found_with_null ⇒ Object
Helper method to render HTTP 404 Bad Request with null “data”.
      91 92 93  | 
    
      # File 'lib/jsonapi/utils/response/renders.rb', line 91 def jsonapi_render_not_found_with_null render json: { data: nil }, status: 200 end  |