Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/djo/tokenie

Generation a friendly token randomically.
https://github.com/djo/tokenie

Last synced: 26 days ago
JSON representation

Generation a friendly token randomically.

Awesome Lists containing this project

README

        

= Tokenie
{}[http://travis-ci.org/Djo/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