Class: Factorix::HTTP::CachedResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/factorix/http/cached_response.rb,
sig/factorix/http/cache_decorator.rbs

Overview

Response wrapper for cached data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, uri: nil) ⇒ CachedResponse

Returns a new instance of CachedResponse.

Parameters:

  • body (String) —

    cached response body



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.

Returns:

  • (String)


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.

Returns:

  • (Integer)


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.

Returns:

  • (Hash[String, Array[String]])


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

Returns:

  • (Integer) —

    body size in bytes



37
# File 'lib/factorix/http/cached_response.rb', line 37

def content_length = @body.bytesize

#success? ⇒ Boolean

Always returns true for cached responses

Returns:

  • (Boolean) —

    true



32
# File 'lib/factorix/http/cached_response.rb', line 32

def success? = true