Module: Hobby::RPC::User
- Defined in:
- lib/hobby/rpc.rb
Class Method Summary collapse
-
.find_by_token(token) ⇒ Object
Accepts a ‘token`(String).
- .included(role) ⇒ Object
- .roles ⇒ Object
Instance Method Summary collapse
Class Method Details
.find_by_token(token) ⇒ Object
Accepts a ‘token`(String).
This method is for finding a user. It is expected by Hobby::Auth: github.com/ch1c0t/hobby-auth
If you store all active sessions in one place, you might want to redefine it, since the default implementation below is O(n).
Still, it seems to be a reasonable default, because it’s ready, by default, for cases when there might be multiple kinds of tokens and multiple ways to store them. And, thanks to Ruby, it’s easy to redefine it when it’s not needed.
Returns a user or nil(if a session for such token does not exist).
24 25 26 27 28 29 30 31 |
# File 'lib/hobby/rpc.rb', line 24 def self.find_by_token token roles.each do |role| if user = (role.find_by_token token) return user end end return nil end |
.included(role) ⇒ Object
36 37 38 |
# File 'lib/hobby/rpc.rb', line 36 def self.included role roles << role end |
.roles ⇒ Object
4 5 6 |
# File 'lib/hobby/rpc.rb', line 4 def self.roles @roles ||= [] end |
Instance Method Details
#can?(_function) ⇒ Boolean
33 34 |
# File 'lib/hobby/rpc.rb', line 33 def can? _function end |