<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,15 +1,21 @@
 module Defv
   module SessionLifetime
     module ClassMethods
+      # Set the session expiring
+      #
+      # Options:
+      #   * :time - After how much time of inactivity should the session be invalidated. Default is 1 hour
+      #   * :redirect_to - Where should we redirect the user to once their session has expired
+      #   * :redirect_with - Use a function to redirect the user. Overrides redirect_to.
+      #   * :on_expiry - Takes a Proc or a lamba which gives you a callback after the session invalidation. This is useful for setting a flash message or something in the database.
       def expires_session options = {}
-        cattr_accessor :_session_expiry
-        cattr_accessor :_redirect_to
-        cattr_accessor :_on_expiry
-        
-        self._session_expiry = options[:time] || 1.hour
-        self._redirect_to = options[:redirect_to] || '/'
-        self._on_expiry = options[:on_expiry]
+        options.reverse_merge!({
+          :time =&gt; 1.hour,
+          :redirect_to =&gt; '/'
+        })
         
+        write_inheritable_attribute &quot;@session_expiry_options&quot;, options
+    
         self.before_filter :check_session_lifetime
       end
     end
@@ -18,17 +24,28 @@ module Defv
         protected
         
         def check_session_lifetime
-          if session[:updated_at] &amp;&amp; session[:updated_at] + self._session_expiry &lt; Time.now
+          # Get the attribute set by expires_session
+          options = self.class.read_inheritable_attribute('@session_expiry_options')
+
+          # Session is expired
+          if session[:updated_at] &amp;&amp; session[:updated_at] + options[:time] &lt; Time.now
             reset_session
-            redirect_to self._redirect_to
             
-            if self._on_expiry
-              if self._on_expiry.arity == 1
-                self._on_expiry.call(self)
+            # Redirect (either with redirect_with or redirect_to)
+            if options[:redirect_with]
+              self.send(options[:redirect_with])
+            else
+              redirect_to options[:redirect_to]
+            end
+            
+            # Call the on_expiry proc if one is given
+            if options[:on_expiry]
+              if options[:on_expiry].arity == 1
+                options[:on_expiry].call(self)
               else
-                instance_eval(&amp;self._on_expiry)
+                instance_eval(&amp;options[:on_expiry])
               end
-            elsif self.methods.include?('on_expiry')
+            elsif self.methods.include?('on_expiry') # Legacy, call the on_expiry method if one is defined
               self.send(:on_expiry) 
             end
           else</diff>
      <filename>lib/defv/session_lifetime.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7b05b08bb418856e823c55e90f070876afe03b07</id>
    </parent>
  </parents>
  <author>
    <name>Jan De Poorter</name>
    <email>jan@defv.be</email>
  </author>
  <url>http://github.com/DefV/session_lifetime/commit/387b186478e5ee8650c5c0e8ba6948b0acda42c3</url>
  <id>387b186478e5ee8650c5c0e8ba6948b0acda42c3</id>
  <committed-date>2009-02-18T07:52:30-08:00</committed-date>
  <authored-date>2009-02-18T07:52:30-08:00</authored-date>
  <message>Got rid of the cattr_accessors, added the redirect_with options.

Also added some documentation in-code for other people</message>
  <tree>58d1bf698c66d690626ee222ec81bddec6e1ca20</tree>
  <committer>
    <name>Jan De Poorter</name>
    <email>jan@defv.be</email>
  </committer>
</commit>
