Class: Maquina::Current
- Inherits:
-
ActiveSupport::CurrentAttributes
- Object
- ActiveSupport::CurrentAttributes
- Maquina::Current
- Defined in:
- app/models/maquina/current.rb
Overview
A class representing the Current context in the Maquina module. Manages per-request global state for the current user session.
Attributes
active_session
-
The current active session for the request.
user
-
The current authenticated user.
membership
-
The current user’s default membership.
Usage
Current attributes are cleared between requests and provide a thread-safe way to handle request-specific data. They are automatically reset after each request.
Instance Method Summary collapse
-
#active_session=(value) ⇒ Object
Sets the active session and updates related attributes.
-
#management? ⇒ Boolean
Checks if the current user has management privileges.
-
#signed_in? ⇒ Boolean
Checks if there is a valid signed-in session.
Instance Method Details
#active_session=(value) ⇒ Object
Sets the active session and updates related attributes
When setting a new active session, automatically updates the current user and their default membership.
Args:
-
value -> Maquina::ActiveSession: The active session to set
44 45 46 47 48 |
# File 'app/models/maquina/current.rb', line 44 def active_session=(value) super self.user = value&.user self.membership = user.default_membership end |
#management? ⇒ Boolean
Checks if the current user has management privileges
Returns:
-
true -> if the current user has management access
-
false -> if the current user does not have management access
55 56 57 |
# File 'app/models/maquina/current.rb', line 55 def management? user.management? end |
#signed_in? ⇒ Boolean
Checks if there is a valid signed-in session
Returns:
-
true -> if there is an active, non-expired, non-blocked session
-
false -> if there is no active session or the session is invalid
27 28 29 30 31 32 33 34 35 |
# File 'app/models/maquina/current.rb', line 27 def signed_in? if active_session.blank? || active_session.expired? || active_session.blocked? self.user = nil self.membership = nil false end true end |