Module: Shrinker::Token

Extended by:
Token
Included in:
Token
Defined in:
lib/shrinker/token.rb

Instance Method Summary collapse

Instance Method Details

#fetch_unique_token(backend, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/shrinker/token.rb', line 7

def fetch_unique_token(backend, options = {})
  need_token = true

  while need_token
    token      = generate(options)
    need_token = backend.used_token?(token)
  end

  token
end

#generate(options = {}) ⇒ Object



18
19
20
21
# File 'lib/shrinker/token.rb', line 18

def generate(options = {})
  prefix = options[:prefix]
  Digest::MD5.hexdigest("#{prefix}__#{rand(99999)}")[-12..-1]
end