Class: Skr::UserProxy
- Inherits:
-
Object
- Object
- Skr::UserProxy
- Defined in:
- lib/skr/user_proxy.rb
Overview
The UserProxy is a stand-in for the real user model that will be implementation specific by the user of Stockor Core
Class Method Summary collapse
-
.current ⇒ Object, FixNum
The user who’s currently interacting with Stockor.
-
.current_id ⇒ Fixnum
Retrieve the current id of the user we’re proxying for.
-
.scoped_to(user) ⇒ UserProxy
sets the user for the duration of the block.
Class Method Details
.current ⇒ Object, FixNum
The user who’s currently interacting with Stockor. Defaults to 0, indicating anonymous or unknown
10 11 12 |
# File 'lib/skr/user_proxy.rb', line 10 def self.current Thread.current[:skr_user_proxy] end |
.current_id ⇒ Fixnum
Retrieve the current id of the user we’re proxying for. get’s a bit complicated since we can proxy both for a user object or just the user’s id
18 19 20 21 22 23 24 |
# File 'lib/skr/user_proxy.rb', line 18 def self.current_id if self.current.nil? 0 else self.current.is_a?(Fixnum) ? self.current : self.current.id end end |
.scoped_to(user) ⇒ UserProxy
sets the user for the duration of the block
53 54 55 56 57 58 |
# File 'lib/skr/user_proxy.rb', line 53 def self.scoped_to( user ) prev_user, Thread.current[:skr_user_proxy] = self.current, user yield user ensure Thread.current[:skr_user_proxy] = prev_user end |