Class: Whodunit::Current
- Inherits:
-
ActiveSupport::CurrentAttributes
- Object
- ActiveSupport::CurrentAttributes
- Whodunit::Current
- Defined in:
- lib/whodunit/current.rb
Overview
Thread-safe current user context using Rails CurrentAttributes.
This class provides a thread-safe way to store the current user for auditing purposes. It leverages Rails’ CurrentAttributes functionality to ensure proper isolation across threads and requests.
Instance Attribute Summary collapse
-
#user ⇒ Integer?
The current user ID.
Class Method Summary collapse
-
.original_user_assignment ⇒ Object
Store the original user= method before we override it.
-
.reset ⇒ Object
Override reset to ensure our custom setter is preserved.
-
.user=(user) ⇒ Integer?
Set the current user by object or ID.
-
.user_id ⇒ Integer?
Get the current user ID for database storage.
Instance Attribute Details
#user ⇒ Integer?
Returns the current user ID.
32 |
# File 'lib/whodunit/current.rb', line 32 attribute :user |
Class Method Details
.original_user_assignment ⇒ Object
Store the original user= method before we override it
36 |
# File 'lib/whodunit/current.rb', line 36 alias original_user_assignment user= |
.reset ⇒ Object
Override reset to ensure our custom setter is preserved
55 56 57 58 59 |
# File 'lib/whodunit/current.rb', line 55 def reset super # Redefine our custom setter after reset _redefine_user_setter end |
.user=(user) ⇒ Integer?
Set the current user by object or ID.
Accepts either a user object (responds to #id) or a user ID directly. The user ID is stored for database operations.
49 50 51 52 |
# File 'lib/whodunit/current.rb', line 49 def user=(user) value = user.respond_to?(:id) ? user.id : user original_user_assignment(value) end |
.user_id ⇒ Integer?
Get the current user ID for database storage.
74 75 76 |
# File 'lib/whodunit/current.rb', line 74 def self.user_id user end |