Module: CurrentUser
- Defined in:
- lib/sixarm_ruby_current_user.rb
Instance Method Summary collapse
-
#current_user(ops = {}) ⇒ Object
Get the current user.
-
#current_user=(user) ⇒ Object
Set the current user Return the current user.
-
#current_user? ⇒ Boolean
Is there a current user in the Rails session?.
Instance Method Details
#current_user(ops = {}) ⇒ Object
Get the current user.
This calls User.find with the current_user_id
The current user is memoized as @current_user. To reload, pass :reload => true
Return the current user, or nil if the current user id is not set, or raise an exception if the current iser id is invalid
21 22 23 24 |
# File 'lib/sixarm_ruby_current_user.rb', line 21 def current_user(ops={}) if ops[:reload] then @current_user=nil end @current_user ||= (current_user_id ? User.find(current_user_id) : nil) end |
#current_user=(user) ⇒ Object
Set the current user Return the current user
37 38 39 40 |
# File 'lib/sixarm_ruby_current_user.rb', line 37 def current_user=(user) self.current_user_id = (user ? user.id : nil) @current_user = user end |
#current_user? ⇒ Boolean
Is there a current user in the Rails session?
29 30 31 |
# File 'lib/sixarm_ruby_current_user.rb', line 29 def current_user? !!self.current_user end |