Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/djo/tokenie
- Owner: djo
- License: mit
- Created: 2011-09-18T16:16:27.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2012-01-30T21:25:42.000Z (almost 13 years ago)
- Last Synced: 2024-04-26T19:48:29.531Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 105 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- Changelog: CHANGELOG.rdoc
- License: LICENSE
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