https://github.com/johnvuko/jt-rails-tokenizable
Token generation for ActiveRecord models in Ruby On Rails
https://github.com/johnvuko/jt-rails-tokenizable
Last synced: about 1 month ago
JSON representation
Token generation for ActiveRecord models in Ruby On Rails
- Host: GitHub
- URL: https://github.com/johnvuko/jt-rails-tokenizable
- Owner: johnvuko
- License: mit
- Created: 2015-07-08T21:07:13.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-03-31T21:09:58.000Z (about 9 years ago)
- Last Synced: 2026-04-29T05:07:52.470Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JTRailsTokenizable
[](http://badge.fury.io/rb/jt-rails-tokenizable)
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
```ruby
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:
```ruby
my_instance.generate_new_token(:my_token_field)
my_instance.save
# or directly
my_instance.generate_new_token!(:my_token_field)
```
## Author
- [Jonathan Tribouharet](https://github.com/jonathantribouharet) ([@johntribouharet](https://twitter.com/johntribouharet))
## License
JTRailsTokenizable is released under the MIT license. See the LICENSE file for more info.