Class: Factorix::HTTP::CachedResponse
- Inherits:
-
Object
- Object
- Factorix::HTTP::CachedResponse
- Defined in:
- lib/factorix/http/cached_response.rb
Overview
Response wrapper for cached data
Provides a simple response object that can be constructed from a cached body string, without requiring an actual HTTP response. Used by CacheDecorator to return cached content with a uniform interface matching Response objects.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#content_length ⇒ Integer
Get content length from body size.
-
#initialize(body, uri: nil) ⇒ CachedResponse
constructor
A new instance of CachedResponse.
-
#success? ⇒ Boolean
Always returns true for cached responses.
Constructor Details
#initialize(body, uri: nil) ⇒ CachedResponse
Returns a new instance of CachedResponse.
19 20 21 22 23 24 |
# File 'lib/factorix/http/cached_response.rb', line 19 def initialize(body, uri: nil) @body = body @code = 200 @headers = {"content-type" => ["application/octet-stream"]} @uri = uri end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/factorix/http/cached_response.rb', line 12 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
13 14 15 |
# File 'lib/factorix/http/cached_response.rb', line 13 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
14 15 16 |
# File 'lib/factorix/http/cached_response.rb', line 14 def headers @headers end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
15 16 17 |
# File 'lib/factorix/http/cached_response.rb', line 15 def uri @uri end |
Instance Method Details
#content_length ⇒ Integer
Get content length from body size
37 |
# File 'lib/factorix/http/cached_response.rb', line 37 def content_length = @body.bytesize |
#success? ⇒ Boolean
Always returns true for cached responses
Since only successful responses are cached, all CachedResponse objects represent successful HTTP interactions.
32 |
# File 'lib/factorix/http/cached_response.rb', line 32 def success? = true |