Created
November 19, 2012 17:11
-
-
Save defp/4111987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment