class CryptIdent::UpdateSessionExpiry
Produce an updated Session Expiration timestamp, to support session management and prevent prematurely Signing Out a User.
This class *is not* part of the published API. @private
Constants
- GUEST_YEARS
- SECONDS_PER_YEAR
Attributes
guest_user[R]
session_expiry[R]
Public Class Methods
new()
click to toggle source
# File lib/crypt_ident/update_session_expiry.rb, line 84 def initialize config = CryptIdent.config @guest_user = config.guest_user @session_expiry = config.session_expiry end
Public Instance Methods
call(session_data = {})
click to toggle source
# File lib/crypt_ident/update_session_expiry.rb, line 90 def call(session_data = {}) result_data = session_data.to_hash if guest_user?(session_data) result_data.merge(guest_data) else result_data.merge(updated_expiry) end end
Private Instance Methods
guest_data()
click to toggle source
# File lib/crypt_ident/update_session_expiry.rb, line 107 def guest_data { expires_at: Time.now + GUEST_YEARS * SECONDS_PER_YEAR } end
guest_user?(session_data)
click to toggle source
# File lib/crypt_ident/update_session_expiry.rb, line 111 def guest_user?(session_data) user = session_data[:current_user] || guest_user # If the `session_data` in fact came from Rack session data, then any # objects (such as a `User` Entity) have been converted to JSON-compatible # types. Hanami Entities can be implicitly converted to and from Hashes of # their attributes, so this part's easy... User.new(user).guest? end
updated_expiry()
click to toggle source
# File lib/crypt_ident/update_session_expiry.rb, line 120 def updated_expiry { expires_at: Time.now + session_expiry } end