Class: Slimer::ApiKey

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/slimer/api_key.rb

Overview

A Sequel::Model wrapper around the api_keys table

Class Method Summary collapse

Class Method Details

.generate(name) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/slimer/api_key.rb', line 8

def self.generate(name)
  new_token = loop do
    generated_token = SecureRandom.urlsafe_base64
    break generated_token unless token_exists?(generated_token)
  end

  create name: name, token: new_token
end

.token_exists?(token) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/slimer/api_key.rb', line 17

def self.token_exists?(token)
  ApiKey.where(token: token).count.positive?
end