]> projects.mako.cc - selectricity/blob - vendor/plugins/dynamic_sessions/lib/dynamic_session_expiry.rb
turned off memcache as it was causing trouble
[selectricity] / vendor / plugins / dynamic_sessions / lib / dynamic_session_expiry.rb
1 # Provides the ability to have session cookies for your Rails app calculated
2 # relative to the current time.
3 #
4 # In your environment.rb file (or in the environments/*.rb file of your choice),
5 # do something like the following:
6 #
7 #   CGI::Session.expire_after 1.month
8 #
9 # Session cookies will then expire one month after the session was created. This
10 # differs from the usual session cookie behavior in that the expiration date is
11 # not a fixed time, but rather relative to the current time.
12
13 class CGI
14   class Session
15     @@session_expiration_offset = 0
16     
17     def self.session_expiration_offset
18       @@session_expiration_offset
19     end
20     
21     def self.session_expiration_offset=(value)
22       @@session_expiration_offset = value
23     end
24
25     def self.expire_after(value)
26       @@session_expiration_offset = value
27     end
28     
29     alias :initialize_without_dynamic_session_expiration :initialize #:nodoc:
30     def initialize(request, option={}) #:nodoc:
31       if @@session_expiration_offset && @@session_expiration_offset > 0
32         option['session_expires'] = Time.now + @@session_expiration_offset
33       end
34       initialize_without_dynamic_session_expiration(request, option)
35     end
36     
37   end
38 end

Benjamin Mako Hill || Want to submit a patch?