Module: AutoSessionTimeout::ClassMethods

Defined in:
lib/auto_session_timeout.rb

Instance Method Summary collapse

Instance Method Details

#auto_session_timeout(seconds = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/auto_session_timeout.rb', line 8

def auto_session_timeout(seconds=nil)
  prepend_before_action do |c|
    if session_expired?(c) && !signing_in?(c)
      handle_session_reset(c)
    else
      unless c.request.original_url.start_with?(c.send(:active_url))
        offset = seconds || (current_user.respond_to?(:auto_timeout) ? current_user.auto_timeout : nil)
        c.session[:auto_session_expires_at] = Time.now + offset if offset && offset > 0
      end
    end
  end
end

#auto_session_timeout_actionsObject



21
22
23
24
# File 'lib/auto_session_timeout.rb', line 21

def auto_session_timeout_actions
  define_method(:active) { render_session_status }
  define_method(:timeout) { render_session_timeout }
end