Class: Lotus::Action::CookieJar

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/action/cookie_jar.rb

Overview

A set of HTTP Cookies

It acts as an Hash

See Also:

  • Lotus::Action::Cookies#cookies

Since:

  • 0.1.0

Constant Summary collapse

HTTP_HEADER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The key that returns raw cookies from the Rack env

Since:

  • 0.1.0

'HTTP_COOKIE'.freeze
'rack.request.cookie_hash'.freeze
'rack.request.cookie_string'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(env, headers) ⇒ CookieJar

Initialize the CookieJar

Parameters:

  • env (Hash)

    a raw Rack env

  • headers (Hash)

    the response headers

Since:

  • 0.1.0



39
40
41
42
# File 'lib/lotus/action/cookie_jar.rb', line 39

def initialize(env, headers)
  @_headers = headers
  @cookies  = Utils::Hash.new(extract(env)).symbolize!
end

Instance Method Details

#[](key) ⇒ Object?

Returns the object associated with the given key

Parameters:

  • key (Symbol)

    the key

Returns:

  • (Object, nil)

    return the associated object, if found

Since:

  • 0.2.0



63
64
65
# File 'lib/lotus/action/cookie_jar.rb', line 63

def [](key)
  @cookies[key]
end

#[]=(key, value) ⇒ void

This method returns an undefined value.

Associate the given value with the given key and store them

Parameters:

  • key (Symbol)

    the key

  • value (Object)

    the value

Since:

  • 0.2.0



75
76
77
# File 'lib/lotus/action/cookie_jar.rb', line 75

def []=(key, value)
  @cookies[key] = value
end

#finishvoid

This method returns an undefined value.

Finalize itself, by setting the proper headers to add and remove cookies, before the response is returned to the webserver.

See Also:

  • Lotus::Action::Cookies#finish

Since:

  • 0.1.0



52
53
54
# File 'lib/lotus/action/cookie_jar.rb', line 52

def finish
  @cookies.each {|k,v| v.nil? ? delete_cookie(k) : set_cookie(k, v) }
end