Project

tokenie

0.0
No commit activity in last 3 years
No release in over 3 years
Generation a friendly token randomically
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.8.0
 Project Readme

Tokenie¶ ↑

<img src=“https://secure.travis-ci.org/Djo/tokenie.png” />

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