Class: Plezi::Controller::Cookies
- Inherits:
-
Hash
- Object
- Hash
- Plezi::Controller::Cookies
- Defined in:
- lib/plezi/controller/cookies.rb
Overview
The cookie jar class. Controllers have an instance of this class named ‘cookies`.
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Reads a cookie from either the request cookie Hash or the new cookies Hash.
-
#[]=(key, value) ⇒ Object
Sets (or deletes) a cookie.
-
#initialize(request, response) ⇒ Cookies
constructor
A new instance of Cookies.
Constructor Details
#initialize(request, response) ⇒ Cookies
Returns a new instance of Cookies.
6 7 8 9 |
# File 'lib/plezi/controller/cookies.rb', line 6 def initialize(request, response) @request = request @response = response end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/plezi/controller/cookies.rb', line 5 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/plezi/controller/cookies.rb', line 5 def response @response end |
Instance Method Details
#[](key) ⇒ Object
Reads a cookie from either the request cookie Hash or the new cookies Hash.
12 13 14 15 16 17 18 19 20 |
# File 'lib/plezi/controller/cookies.rb', line 12 def[](key) if key.is_a? Symbol super(key) || super(key.to_s) || @request.[key] || @request.[key.to_s] elsif key.is_a? String super(key) || super(key.to_sym) || @request.[key] || @request.[key.to_sym] else super(key) || @request.[key] end end |
#[]=(key, value) ⇒ Object
Sets (or deletes) a cookie. New cookies are placed in the new cookie Hash and are accessible only to the controller that created them.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/plezi/controller/cookies.rb', line 23 def[]=(key, value) if value.nil? @response. 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. key, value value = value[:value] if value.is_a? Hash super end |