Class: Innate::Session
- Inherits:
-
Object
- Object
- Innate::Session
- Includes:
- Optioned
- Defined in:
- lib/innate/session.rb,
lib/innate/session/flash.rb
Overview
Mostly ported from Ramaze, but behaves lazy, no session will be created if no session is used.
We keep session data in memory until #flush is called, at which point it will be persisted completely into the cache, no question asked.
You may store anything in here that you may also store in the corresponding store, usually it’s best to keep it to things that are safe to Marshal.
The default time of expiration is *
Time.at(2147483647) # => Tue Jan 19 12:14:07 +0900 2038
Hopefully we all have 64bit systems by then.
Defined Under Namespace
Classes: Flash
Instance Attribute Summary collapse
-
#cookie_set ⇒ Object
readonly
Returns the value of attribute cookie_set.
-
#flash ⇒ Object
readonly
Returns the value of attribute flash.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #cache_sid ⇒ Object
- #clear ⇒ Object
- #cookie ⇒ Object
- #delete(key) ⇒ Object
- #flush(response = @response) ⇒ Object
-
#initialize(request, response) ⇒ Session
constructor
A new instance of Session.
- #inspect ⇒ Object
- #sid ⇒ Object
Methods included from Optioned
Constructor Details
Instance Attribute Details
#cookie_set ⇒ Object (readonly)
Returns the value of attribute cookie_set.
34 35 36 |
# File 'lib/innate/session.rb', line 34 def @cookie_set end |
#flash ⇒ Object (readonly)
Returns the value of attribute flash.
34 35 36 |
# File 'lib/innate/session.rb', line 34 def flash @flash end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
34 35 36 |
# File 'lib/innate/session.rb', line 34 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
34 35 36 |
# File 'lib/innate/session.rb', line 34 def response @response end |
Instance Method Details
#[](key) ⇒ Object
47 48 49 |
# File 'lib/innate/session.rb', line 47 def [](key) cache_sid[key] end |
#[]=(key, value) ⇒ Object
43 44 45 |
# File 'lib/innate/session.rb', line 43 def []=(key, value) cache_sid[key] = value end |
#cache_sid ⇒ Object
60 61 62 |
# File 'lib/innate/session.rb', line 60 def cache_sid @cache_sid ||= cache[sid] || {} end |
#clear ⇒ Object
55 56 57 58 |
# File 'lib/innate/session.rb', line 55 def clear cache.delete(sid) @cache_sid = nil end |
#cookie ⇒ Object
77 78 79 |
# File 'lib/innate/session.rb', line 77 def @request.[.key] end |
#delete(key) ⇒ Object
51 52 53 |
# File 'lib/innate/session.rb', line 51 def delete(key) cache_sid.delete(key) end |
#flush(response = @response) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/innate/session.rb', line 64 def flush(response = @response) return if !@cache_sid or @cache_sid.empty? flash.rotate! ttl = (Time.at([:expires]) - Time.now).to_i cache.store(sid, cache_sid, :ttl => ttl) (response) end |
#inspect ⇒ Object
81 82 83 |
# File 'lib/innate/session.rb', line 81 def inspect cache.inspect end |
#sid ⇒ Object
73 74 75 |
# File 'lib/innate/session.rb', line 73 def sid @sid ||= || generate_sid end |