Class: Pakyow::Application::Connection::Session::Cookie

Inherits:
Base
  • Object
show all
Defined in:
lib/pakyow/application/connection/session/cookie.rb

Instance Method Summary collapse

Methods inherited from Base

#pp

Constructor Details

#initialize(connection, options) ⇒ Cookie

Returns a new instance of Cookie.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pakyow/application/connection/session/cookie.rb', line 15

def initialize(connection, options)
  if (cookie = connection.cookies[options.name]) && cookie.is_a?(Support::IndifferentHash)
    super(connection, options, Support::IndifferentHash.new(cookie[:value].to_h))
    connection.cookies[options.name][:value] = self
  else
    super(connection, options, deserialize(connection, options))
    connection.cookies[options.name] = Support::IndifferentHash.new(
      domain: options.domain,
      path: options.path,
      max_age: options.max_age,
      expires: options.expires,
      secure: options.secure,
      http_only: options.http_only,
      same_site: options.same_site,
      value: self
    )

    # Update the original cookie value so we can compare for changes.
    #
    connection.update_request_cookie(options.name, self.dup)
  end
end

Instance Method Details

#to_sObject



38
39
40
41
42
43
44
# File 'lib/pakyow/application/connection/session/cookie.rb', line 38

def to_s
  Base64.urlsafe_encode64(
    Pakyow.verifier.sign(
      Marshal.dump(to_h)
    )
  )
end