Module: Tokenie

Defined in:
lib/tokenie.rb,
lib/tokenie/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.friendly(options = {}) ⇒ Object

Generates a friendly string randomically

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'lib/tokenie.rb', line 6

def self.friendly(options = {})
  length = options[:length] || 6
  raise ArgumentError, "'length' must be in range (2..16)" if length < 2 || length > 16

  loop do
    token = SecureRandom.base64(15).tr('+/=1lIO0o', 'abcdefghj')[0, length]
    break token unless block_given? && yield(token)
  end
end