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
Returns true if the other is a Response with an equal body, equal message and equal headers.
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(body, message = 200, headers = {}) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
Returns true if code is 2xx, false otherwise.
Constructor Details
#initialize(body, message = 200, headers = {}) ⇒ Response
Returns a new instance of Response.
324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/active_resource/http_mock.rb', line 324 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 self["Content-Length"] = @body.nil? ? "0" : body.size.to_s end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
322 323 324 |
# File 'lib/active_resource/http_mock.rb', line 322 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
322 323 324 |
# File 'lib/active_resource/http_mock.rb', line 322 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
322 323 324 |
# File 'lib/active_resource/http_mock.rb', line 322 def headers @headers end |
#message ⇒ Object
Returns the value of attribute message.
322 323 324 |
# File 'lib/active_resource/http_mock.rb', line 322 def @message end |
Instance Method Details
#==(other) ⇒ Object
Returns true if the other is a Response with an equal body, equal message and equal headers. Otherwise it returns false.
352 353 354 355 356 357 358 |
# File 'lib/active_resource/http_mock.rb', line 352 def ==(other) if other.is_a?(Response) other.body == body && other. == && other.headers == headers else false end end |
#[](key) ⇒ Object
342 343 344 |
# File 'lib/active_resource/http_mock.rb', line 342 def [](key) headers[key] end |
#[]=(key, value) ⇒ Object
346 347 348 |
# File 'lib/active_resource/http_mock.rb', line 346 def []=(key, value) headers[key] = value end |
#success? ⇒ Boolean
Returns true if code is 2xx, false otherwise.
338 339 340 |
# File 'lib/active_resource/http_mock.rb', line 338 def success? code.in?(200..299) end |