Generation a friendly token randomically.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.travis.yml
CHANGELOG.rdoc
Gemfile
Gemfile.lock
LICENSE
README.rdoc
Rakefile
tokenie.gemspec

README.rdoc

Tokenie

Tokenie gem provides generation friendly token randomically. Symbols '+/=1lIO0o' are replaced with 'abcdefghj'. Inspired by devise's friendly token generation.

Installation

Install as a gem from RubyGems:

gem install tokenie

Getting Started

Generate a token:

require 'tokenie'
Tokenie.friendly # => "De6paD"

By default it uses 6 characters for the end-string. To change it use :length option:

Tokenie.friendly(:length => 8) # => "gRaxwBg7"

If you want to ensure uniqueness you should provide a block which returns false in the case that means a token is not included in your storage:

existing_tokens = ['qwerty1', 'qwerty2', 'qwerty3']
Tokenie.friendly { |token| existing_tokens.include? token }

An example with ActiveRecord:

Tokenie.friendly { |t| self.class.exists?(:token => t) }

Dependencies

  • Ruby 1.8.7 or later