Class: Picombo::Session
- Inherits:
-
Object
- Object
- Picombo::Session
- Includes:
- Singleton
- Defined in:
- lib/classes/session.rb
Overview
Session handling class
In essense, a proxy to the rack session handling methods.
Example usage
Writing cookie values Picombo::Session.set(:sample, ‘this is the content of the session var’)
Getting cookie values Picombo::Session.get(:sample)
Instance Method Summary collapse
-
#get(key = nil, default = nil) ⇒ Object
Retrieves a session item defined by key, returns default if item doesn’t exist You can retreive the entire session by omiting the key paramter.
-
#init(req) ⇒ Object
Initializes the request for cookies.
-
#set(key, val) ⇒ Object
Sets a session item defined by key to val.
-
#unset(key) ⇒ Object
Unsets a session variable.
Instance Method Details
#get(key = nil, default = nil) ⇒ Object
Retrieves a session item defined by key, returns default if item doesn’t exist You can retreive the entire session by omiting the key paramter
22 23 24 25 26 27 28 |
# File 'lib/classes/session.rb', line 22 def get(key = nil, default = nil) return @@req.session if key.nil? result = Picombo::Config.key_string(@@req.session, key) return result.nil? ? default : result end |
#init(req) ⇒ Object
Initializes the request for cookies
16 17 18 |
# File 'lib/classes/session.rb', line 16 def init(req) @@req = req end |
#set(key, val) ⇒ Object
Sets a session item defined by key to val
31 32 33 |
# File 'lib/classes/session.rb', line 31 def set(key, val) @@req.session[key] = val end |
#unset(key) ⇒ Object
Unsets a session variable
36 37 38 |
# File 'lib/classes/session.rb', line 36 def unset(key) @@req.session.delete(key) end |