]> git.openstreetmap.org Git - rails.git/blob - lib/session_persistence/session_persistence.rb
7bb51bc465bd97a8b7265d85522b9dfc484e2188
[rails.git] / lib / session_persistence / session_persistence.rb
1 module SessionPersistence
2   private
3   
4   # Override this method if you don't want to use session[:_remember_for].
5   def session_persistence_key
6     :_remember_for
7   end
8
9   # Persist the session.
10   #
11   #   session_expires_after 1.hour
12   #   session_expires_after 2.weeks
13   def session_expires_after(seconds)
14     session[session_persistence_key] = seconds 
15   end
16   
17   # Expire the session.
18   def session_expires_automatically
19     session.delete(session_persistence_key)
20   end
21   alias_method :expire_session, :session_expires_automatically
22   
23   def _persist_session
24     if session[session_persistence_key]
25       env["rack.session.options"][:expire_after] = session[session_persistence_key]
26     end
27   end
28 end