jt-rails-tokenizable 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +43 -0
- data/jt-rails-tokenizable.gemspec +13 -0
- data/lib/jt-rails-tokenizable.rb +40 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3986f0e86966098e041d95c44a3991c1b28bdbba
|
4
|
+
data.tar.gz: 846fb4c285e0a5c8f7e11a3cfa55803da70b7c0b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 903d821e006da9885d7fa220ed4725f968e759e43987c961d9b40f432f11c8138c8a26664e9dc692321ff20f412bdf15540995a8528c674571e984109e93a6d7
|
7
|
+
data.tar.gz: e7c426838eead5846be6d5862f80f709263d55529862106aaecd0d2cb6277d286bd5b23f13cf124204fabd1236bd984830d0a92d85e31c5eb75ffd8ca74d1b6e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 Jonathan Tribouharet
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# JTRailsTokenizable
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/jt-rails-tokenizable.svg)](http://badge.fury.io/rb/jt-rails-tokenizable)
|
4
|
+
|
5
|
+
JTRailsTokenizable generates tokens for ActiveRecord models in Ruby On Rails.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
JTRailsTokenizable is distributed as a gem, which is how it should be used in your app.
|
10
|
+
|
11
|
+
Include the gem in your Gemfile:
|
12
|
+
|
13
|
+
gem 'jt-rails-tokenizable', '~> 1.0'
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Basic usage
|
18
|
+
|
19
|
+
Include `JT::Rails::Tokenizable` in your model:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class User < ActiveRecord::Base
|
23
|
+
include JT::Rails::Tokenizable
|
24
|
+
|
25
|
+
tokenize :my_token_field
|
26
|
+
...
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
A new unique token is generated at the creation of the model. You can generate a new token with:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
my_instance.generate_new_token(:my_token_field)
|
34
|
+
my_instance.save
|
35
|
+
```
|
36
|
+
|
37
|
+
## Author
|
38
|
+
|
39
|
+
- [Jonathan Tribouharet](https://github.com/jonathantribouharet) ([@johntribouharet](https://twitter.com/johntribouharet))
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
JTRailsTokenizable is released under the MIT license. See the LICENSE file for more info.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'jt-rails-tokenizable'
|
3
|
+
s.summary = "Token generation in Ruby On Rails"
|
4
|
+
s.description = "Generate tokens for ActiveRecord models in Ruby On Rails"
|
5
|
+
s.homepage = 'https://github.com/jonathantribouharet/jt-rails-tokenizable'
|
6
|
+
s.version = '1.0.0'
|
7
|
+
s.files = `git ls-files`.split("\n")
|
8
|
+
s.require_paths = ['lib']
|
9
|
+
s.authors = ['Jonathan TRIBOUHARET']
|
10
|
+
s.email = 'jonathan.tribouharet@gmail.com'
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.platform = Gem::Platform::RUBY
|
13
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module JT
|
2
|
+
module Rails
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
module JT::Rails::Tokenizable
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
before_validation :generate_tokens, on: :create
|
11
|
+
|
12
|
+
mattr_accessor :jt_rails_token_fields do
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
|
19
|
+
def tokenize(field)
|
20
|
+
jt_rails_token_fields << field
|
21
|
+
|
22
|
+
validates field, presence: true, uniqueness: true
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_tokens
|
28
|
+
for field in jt_rails_token_fields
|
29
|
+
generate_new_token(field)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_new_token(field)
|
34
|
+
self[field] = loop do
|
35
|
+
random_token = SecureRandom.hex(128)
|
36
|
+
break random_token unless self.class.exists?(field => random_token)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jt-rails-tokenizable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan TRIBOUHARET
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Generate tokens for ActiveRecord models in Ruby On Rails
|
14
|
+
email: jonathan.tribouharet@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- .gitignore
|
20
|
+
- Gemfile
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- jt-rails-tokenizable.gemspec
|
24
|
+
- lib/jt-rails-tokenizable.rb
|
25
|
+
homepage: https://github.com/jonathantribouharet/jt-rails-tokenizable
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.0.14
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Token generation in Ruby On Rails
|
49
|
+
test_files: []
|