Class: HTTP::Session::Cache::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/http/session/cache/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req, res) ⇒ Entry

Returns a new instance of Entry.



28
29
30
31
# File 'lib/http/session/cache/entry.rb', line 28

def initialize(req, res)
  @request = req
  @response = res
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



21
22
23
# File 'lib/http/session/cache/entry.rb', line 21

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



25
26
27
# File 'lib/http/session/cache/entry.rb', line 25

def response
  @response
end

Class Method Details

.deserialize(h) ⇒ Object

Deserializes from a JSON primitive type.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/http/session/cache/entry.rb', line 6

def deserialize(h)
  req = h[:req]
  req = HTTP::Session::Request.new(HTTP::Request.new(req))

  res = h[:res]
  res[:request] = req
  res[:body] = HTTP::Session::Response::StringBody.new(res[:body])
  res = HTTP::Session::Response.new(HTTP::Response.new(res))

  new(req, res)
end

Instance Method Details

#serializeObject

Serializes to a JSON primitive type.



43
44
45
46
47
48
# File 'lib/http/session/cache/entry.rb', line 43

def serialize
  {
    req: serialize_request,
    res: serialize_response
  }
end

#to_response(req) ⇒ Response

Parameters:

Returns:



35
36
37
38
39
40
# File 'lib/http/session/cache/entry.rb', line 35

def to_response(req)
  h = serialize_response
  h[:request] = req
  h[:body] = HTTP::Session::Response::StringBody.new(h[:body])
  HTTP::Session::Response.new(HTTP::Response.new(h))
end