Class: ActiveRacksource::Response
- Inherits:
-
Object
- Object
- ActiveRacksource::Response
- Defined in:
- lib/active_racksource/response.rb
Overview
A thin wrapper around Rack::Response
ActiveResource expects an HTTP Response object to be formatted in a certain way with the right methods, etc.
This object wraps a Rack::Response and implements an inferface that supports ActiveResource
Some methods called by ActiveResource:
- code
-
string representation of status code, eg. ‘200’ or ‘404’
- message
-
string message, eg. ‘OK’ or ‘Not Found’
- body
-
string response body
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(rack_response) ⇒ Response
constructor
initialize a new ActiveRacksource::Response.
- #message ⇒ Object
-
#method_missing(name, *args) ⇒ Object
by default, fall back to methods on the Rack::Response.
Constructor Details
#initialize(rack_response) ⇒ Response
initialize a new ActiveRacksource::Response
Parameters
- rack_response
-
a Rack::Response instance
23 24 25 |
# File 'lib/active_racksource/response.rb', line 23 def initialize rack_response @rack_response = rack_response end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
by default, fall back to methods on the Rack::Response
44 45 46 |
# File 'lib/active_racksource/response.rb', line 44 def method_missing name, *args @rack_response.send name, *args end |
Instance Method Details
#code ⇒ Object
27 28 29 |
# File 'lib/active_racksource/response.rb', line 27 def code @rack_response.status.to_s end |
#message ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_racksource/response.rb', line 31 def if code.start_with?'2' 'OK' elsif code.start_with?'4' 'Not Found' elsif code.start_with?'3' 'Redirect' else 'Error' end end |