Class: ActiveResource::Response
- Inherits:
-
Object
- Object
- ActiveResource::Response
- Defined in:
- lib/active_resource/http_mock.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(body, message = 200, headers = {}) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(body, message = 200, headers = {}) ⇒ Response
Returns a new instance of Response.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/active_resource/http_mock.rb', line 257 def initialize(body, = 200, headers = {}) @body, @message, @headers = body, .to_s, headers @code = @message[0,3].to_i resp_cls = Net::HTTPResponse::CODE_TO_OBJ[@code.to_s] if resp_cls && !resp_cls.body_permitted? @body = nil end if @body.nil? self['Content-Length'] = "0" else self['Content-Length'] = body.size.to_s end end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
255 256 257 |
# File 'lib/active_resource/http_mock.rb', line 255 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
255 256 257 |
# File 'lib/active_resource/http_mock.rb', line 255 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
255 256 257 |
# File 'lib/active_resource/http_mock.rb', line 255 def headers @headers end |
#message ⇒ Object
Returns the value of attribute message.
255 256 257 |
# File 'lib/active_resource/http_mock.rb', line 255 def @message end |
Instance Method Details
#==(other) ⇒ Object
285 286 287 288 289 290 291 |
# File 'lib/active_resource/http_mock.rb', line 285 def ==(other) if (other.is_a?(Response)) other.body == body && other. == && other.headers == headers else false end end |
#[](key) ⇒ Object
277 278 279 |
# File 'lib/active_resource/http_mock.rb', line 277 def [](key) headers[key] end |
#[]=(key, value) ⇒ Object
281 282 283 |
# File 'lib/active_resource/http_mock.rb', line 281 def []=(key, value) headers[key] = value end |
#success? ⇒ Boolean
273 274 275 |
# File 'lib/active_resource/http_mock.rb', line 273 def success? (200..299).include?(code) end |