Class: RackRabbit::Response
- Inherits:
-
Object
- Object
- RackRabbit::Response
- Defined in:
- lib/rack-rabbit/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
————————————————————————–.
-
#headers ⇒ Object
readonly
————————————————————————–.
-
#status ⇒ Object
readonly
————————————————————————–.
Instance Method Summary collapse
- #failed? ⇒ Boolean
-
#initialize(status, headers, body) ⇒ Response
constructor
A new instance of Response.
-
#succeeded? ⇒ Boolean
————————————————————————–.
-
#to_s ⇒ Object
————————————————————————–.
Constructor Details
#initialize(status, headers, body) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 |
# File 'lib/rack-rabbit/response.rb', line 8 def initialize(status, headers, body) @status = status @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
6 7 8 |
# File 'lib/rack-rabbit/response.rb', line 6 def body @body end |
#headers ⇒ Object (readonly)
6 7 8 |
# File 'lib/rack-rabbit/response.rb', line 6 def headers @headers end |
#status ⇒ Object (readonly)
6 7 8 |
# File 'lib/rack-rabbit/response.rb', line 6 def status @status end |
Instance Method Details
#failed? ⇒ Boolean
20 21 22 |
# File 'lib/rack-rabbit/response.rb', line 20 def failed? !succeeded? end |
#succeeded? ⇒ Boolean
16 17 18 |
# File 'lib/rack-rabbit/response.rb', line 16 def succeeded? (200..299).include?(status) end |
#to_s ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rack-rabbit/response.rb', line 26 def to_s if succeeded? body else case status when RackRabbit::STATUS::BAD_REQUEST then "#{status} Bad Request" when RackRabbit::STATUS::NOT_FOUND then "#{status} Not Found" when RackRabbit::STATUS::FAILED then "#{status} Internal Server Error" else status.to_s end end end |