class Sinapse::Authentication

TODO: get to return the token (if any)

Public Instance Methods

clear() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/sinapse/authentication.rb, line 40
def key
  "sinapse:#{record.class.name}:#{record.to_param}"
end
reset() click to toggle source
# File lib/sinapse/authentication.rb, line 10
def reset
  clear
  generate
end
token_key(token) click to toggle source
# File lib/sinapse/authentication.rb, line 36
def token_key(token)
  "sinapse:tokens:#{token}"
end