Class: Sinapse::Authentication
- Inherits:
-
Struct
- Object
- Struct
- Sinapse::Authentication
- Defined in:
- lib/sinapse/authentication.rb
Overview
TODO: #get to return the token (if any)
Instance Attribute Summary collapse
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record
9 10 11 |
# File 'lib/sinapse/authentication.rb', line 9 def record @record end |
Instance Method Details
#clear ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/sinapse/authentication.rb', line 27 def clear Sinapse.redis do |redis| if token = redis.get(key) redis.del(token_key(token)) redis.del(key) end end end |
#generate ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sinapse/authentication.rb', line 15 def generate Sinapse.redis do |redis| loop do token = Sinapse.generate_token if redis.setnx(token_key(token), record.to_param) redis.set(key, token) return token end end end end |
#key ⇒ Object
40 41 42 |
# File 'lib/sinapse/authentication.rb', line 40 def key "sinapse:#{record.class.name}:#{record.to_param}" end |
#reset ⇒ Object
10 11 12 13 |
# File 'lib/sinapse/authentication.rb', line 10 def reset clear generate end |
#token_key(token) ⇒ Object
36 37 38 |
# File 'lib/sinapse/authentication.rb', line 36 def token_key(token) "sinapse:tokens:#{token}" end |