Class: Session::Check::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/session/check/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/session/check/configuration.rb', line 14

def initialize
  @logged_out_url = '/users/sign_in'
  @check_every_s = 10
  @session_active_proc = ->(controller) {
    user = begin
      controller.current_user
    rescue NoMethodError
      nil
    end
    if user
      expires_in = Session::Check::Devise.expires_in(controller.session)
      { exists: true, expires_in: expires_in }
    else
      { exists: false, expires_in: 0 }
    end
  }
end

Instance Attribute Details

#check_every_sObject

Proc used to determine session state. Called with the controller/helper context as its sole argument. Must return a Hash: { exists: Boolean, expires_in: Integer (seconds) }

Override to customise session detection for non-Devise sessions.



12
13
14
# File 'lib/session/check/configuration.rb', line 12

def check_every_s
  @check_every_s
end

#logged_out_urlObject

Proc used to determine session state. Called with the controller/helper context as its sole argument. Must return a Hash: { exists: Boolean, expires_in: Integer (seconds) }

Override to customise session detection for non-Devise sessions.



12
13
14
# File 'lib/session/check/configuration.rb', line 12

def logged_out_url
  @logged_out_url
end

#session_active_procObject

Proc used to determine session state. Called with the controller/helper context as its sole argument. Must return a Hash: { exists: Boolean, expires_in: Integer (seconds) }

Override to customise session detection for non-Devise sessions.



12
13
14
# File 'lib/session/check/configuration.rb', line 12

def session_active_proc
  @session_active_proc
end

Instance Method Details

#call_session_active_proc(context) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/session/check/configuration.rb', line 32

def call_session_active_proc(context)
  result = session_active_proc.call(context)
  unless result.is_a?(Hash)
    raise ArgumentError,
      "session_active_proc must return a Hash with :exists and :expires_in keys, got #{result.class}"
  end
  normalized = result.transform_keys(&:to_sym)
  { exists: normalized[:exists], expires_in: normalized[:expires_in] }
end