class Plezi::Controller::Cookies

The cookie jar class. Controllers have an instance of this class named `cookies`.

Attributes

request[R]
response[R]

Public Class Methods

new(request, response) click to toggle source
# File lib/plezi/controller/cookies.rb, line 6
def initialize(request, response)
   @request = request
   @response = response
end

Public Instance Methods

[](key) click to toggle source

Reads a cookie from either the request cookie Hash or the new cookies Hash.

Calls superclass method
# File lib/plezi/controller/cookies.rb, line 12
def[](key)
   if key.is_a? Symbol
      super(key) || super(key.to_s) || @request.cookies[key] || @request.cookies[key.to_s]
   elsif key.is_a? String
      super(key) || super(key.to_sym) || @request.cookies[key] || @request.cookies[key.to_sym]
   else
      super(key) || @request.cookies[key]
   end
end
[]=(key, value) click to toggle source

Sets (or deletes) a cookie. New cookies are placed in the new cookie Hash and are accessible only to the controller that created them.

Calls superclass method
# File lib/plezi/controller/cookies.rb, line 23
def[]=(key, value)
   if value.nil?
      @response.delete_cookie key
      delete key
      if key.is_a? Symbol
         delete key.to_s
      elsif key.is_a? String
         delete key.to_sym
      end
      return nil
   end
   @response.set_cookie key, value
   value = value[:value] if value.is_a? Hash
   super
end