Class: Factorix::HTTP::CachedResponse
- Inherits:
-
Object
- Object
- Factorix::HTTP::CachedResponse
- Defined in:
- lib/factorix/http/cached_response.rb,
sig/factorix/http/cache_decorator.rbs
Overview
Response wrapper for cached data
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
Returns the value of attribute body.
-
#code ⇒ Integer
readonly
Returns the value of attribute code.
-
#headers ⇒ Hash[String, Array[String]]
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 ⇒ String (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/factorix/http/cached_response.rb', line 12 def body @body end |
#code ⇒ Integer (readonly)
Returns the value of attribute code.
13 14 15 |
# File 'lib/factorix/http/cached_response.rb', line 13 def code @code end |
#headers ⇒ Hash[String, Array[String]] (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
32 |
# File 'lib/factorix/http/cached_response.rb', line 32 def success? = true |