Skip to content

johnvuko/jt-rails-tokenizable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JTRailsTokenizable

Gem Version

JTRailsTokenizable generates tokens for ActiveRecord models in Ruby On Rails.

Installation

JTRailsTokenizable is distributed as a gem, which is how it should be used in your app.

Include the gem in your Gemfile:

gem 'jt-rails-tokenizable', '~> 1.0'

Usage

Basic usage

class User < ActiveRecord::Base
	tokenize :my_token_field
	tokenize :another_token_field, size: 20, validations: false
	tokenize :another_token_field, size: 20, only_digits: true
	...
end

You can change the size of the token (32 by default, which means 64 caracters) and disable the presence and uniqueness validations. The generation of token is using SecureRandom.hex or SecureRandom.random_number methods.

A new unique token is generated at the creation of the model. You can generate a new token with:

my_instance.generate_new_token(:my_token_field)
my_instance.save

# or directly

my_instance.generate_new_token!(:my_token_field)

Author

License

JTRailsTokenizable is released under the MIT license. See the LICENSE file for more info.

About

Token generation for ActiveRecord models in Ruby On Rails

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages