Class: Onsi::ErrorResponse
- Inherits:
-
Object
- Object
- Onsi::ErrorResponse
- Defined in:
- lib/onsi/error_responder.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #add(status, code, title: nil, details: nil, meta: nil) ⇒ Object
- #as_json ⇒ Object
-
#initialize(status) ⇒ ErrorResponse
constructor
A new instance of ErrorResponse.
- #renderable ⇒ Object
Constructor Details
#initialize(status) ⇒ ErrorResponse
Returns a new instance of ErrorResponse.
113 114 115 116 |
# File 'lib/onsi/error_responder.rb', line 113 def initialize(status) @status = status @errors = [] end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
111 112 113 |
# File 'lib/onsi/error_responder.rb', line 111 def status @status end |
Instance Method Details
#add(status, code, title: nil, details: nil, meta: nil) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/onsi/error_responder.rb', line 118 def add(status, code, title: nil, details: nil, meta: nil) @errors << {}.tap do |err| err[:status] = (status || @status).to_s err[:code] = code err[:title] = title if title.present? err[:detail] = details if details.present? err[:meta] = Hash() if .present? end end |
#as_json ⇒ Object
128 129 130 |
# File 'lib/onsi/error_responder.rb', line 128 def as_json { errors: @errors.as_json } end |
#renderable ⇒ Object
132 133 134 135 136 137 |
# File 'lib/onsi/error_responder.rb', line 132 def renderable { json: as_json, status: status } end |