Sha256: cd1f15877d7fd06310ffc5d394a89a9b18fee3b7fc0bf2fe13c8892b4228c0bb

Contents?: true

Size: 432 Bytes

Versions: 2

Compression:

Stored size: 432 Bytes

Contents

require "tokenie/version"
require 'securerandom'

module Tokenie
  # Generates a friendly string randomically
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tokenie-0.0.3 lib/tokenie.rb
tokenie-0.0.2 lib/tokenie.rb