tokenize_attributes 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.readme +0 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +9 -0
- data/lib/tokenize_attributes/attribute.rb +23 -0
- data/lib/tokenize_attributes/configuration.rb +9 -0
- data/lib/tokenize_attributes/railtie.rb +12 -0
- data/lib/tokenize_attributes/version.rb +3 -0
- data/lib/tokenize_attributes.rb +20 -0
- data/tokenize_attributes.gemspec +35 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a5cce212d66f63c7263b9efb86e7625e1e5d8a9
|
4
|
+
data.tar.gz: 34419dc08ada84bcdc54da53b16458e338cf7875
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f75a078d5c0ced79685e0d64886954784c3f8045fd876e6c450adc9cd955bfc7cd50e59352b74107baab4a57db3084eec7e073fe81ef2317f36b2b3dd88fd26
|
7
|
+
data.tar.gz: 29b475d42283febb965f5526bba4a459818cc7c6e740ba51ac7e2016076862e8a61c028c4f19f9472c1207bf0f75cf8cb9646dd2a1e0c2893ff3b095e8a9259a
|
data/.readme
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tokenize_attributes (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.2.9)
|
10
|
+
activesupport (= 4.2.9)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activerecord (4.2.9)
|
13
|
+
activemodel (= 4.2.9)
|
14
|
+
activesupport (= 4.2.9)
|
15
|
+
arel (~> 6.0)
|
16
|
+
activesupport (4.2.9)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
arel (6.0.4)
|
22
|
+
builder (3.2.3)
|
23
|
+
diff-lcs (1.3)
|
24
|
+
i18n (0.8.6)
|
25
|
+
minitest (5.10.3)
|
26
|
+
rake (10.5.0)
|
27
|
+
rspec (2.99.0)
|
28
|
+
rspec-core (~> 2.99.0)
|
29
|
+
rspec-expectations (~> 2.99.0)
|
30
|
+
rspec-mocks (~> 2.99.0)
|
31
|
+
rspec-core (2.99.2)
|
32
|
+
rspec-expectations (2.99.2)
|
33
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
34
|
+
rspec-mocks (2.99.4)
|
35
|
+
sqlite3 (1.3.13)
|
36
|
+
thread_safe (0.3.6)
|
37
|
+
tzinfo (1.2.3)
|
38
|
+
thread_safe (~> 0.1)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
activerecord (>= 4.0.0)
|
45
|
+
activerecord-jdbcsqlite3-adapter
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec
|
48
|
+
sqlite3
|
49
|
+
tokenize_attributes!
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Alexandre Overtus
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# TokenizeAttributes
|
2
|
+
|
3
|
+
TokenizeAttributes allows to define a tokenized attribute.
|
4
|
+
|
5
|
+
A before validation is generate on the attribute to set a tokenized value on the attribute
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
TokenizeAttributes.configure do |config|
|
11
|
+
config.tokenizer = proc { SecureRandom.hex }
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
#### Single attribute
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class Object
|
21
|
+
tokenized_attribute :authentication_token
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
Override tokenizer proc
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class Object
|
29
|
+
tokenized_attribute :attrb1, proc { SecureRandom.uuid }
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
#### Multiple attributes
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class Object
|
38
|
+
tokenized_attribute :authentication_token
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Override tokenizer proc
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class Object
|
46
|
+
tokenized_attributes :attrb1, :attrb2, proc { SecureRandom.uuid }
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Reset Attrb
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
object = Object.new
|
54
|
+
object.reset_tokenization_for_attrb
|
55
|
+
```
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module TokenizeAttributes
|
2
|
+
module Attribute
|
3
|
+
|
4
|
+
def tokenized_attributes(*attrbs)
|
5
|
+
@method = attrbs.pop if attrbs.last.is_a?(Proc)
|
6
|
+
attrbs.each { |attrb| tokenized_attribute(attrb, @method) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def tokenized_attribute(attrb, method = nil)
|
10
|
+
self.send(:define_method, "reset_tokenization_for_#{attrb}") do
|
11
|
+
loop do
|
12
|
+
token = method.try(:call) || TokenizeAttributes.configuration.tokenizer.call
|
13
|
+
self.public_send("#{attrb}=", token)
|
14
|
+
break unless self.class.where(attrb => token).exists?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before_validation do |record|
|
19
|
+
record.public_send("reset_tokenization_for_#{attrb}") if record.public_send(attrb).blank?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'tokenize_attributes'
|
2
|
+
|
3
|
+
module TokenizeAttributes
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
initializer 'tokenize_attributes.extend_active_record' do
|
7
|
+
ActiveSupport.on_load(:active_record) do
|
8
|
+
ActiveRecord::Base.send :extend, TokenizeAttributes::Attribute
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'tokenize_attributes/configuration'
|
2
|
+
require 'tokenize_attributes/version'
|
3
|
+
require 'tokenize_attributes/attribute'
|
4
|
+
|
5
|
+
# Load rails support
|
6
|
+
require 'simple_enum/railtie' if defined?(Rails)
|
7
|
+
|
8
|
+
module TokenizeAttributes
|
9
|
+
class << self
|
10
|
+
attr_accessor :configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "tokenize_attributes/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tokenize_attributes"
|
8
|
+
spec.version = TokenizeAttributes::VERSION
|
9
|
+
spec.authors = ["Alexandre Overtus"]
|
10
|
+
spec.email = ["a.overtus@live.be"]
|
11
|
+
spec.summary = %q{Tokenize attributes in active record object.}
|
12
|
+
spec.description = %q{Tokenize attributes in active record object.}
|
13
|
+
spec.homepage = "https://github.com/aovertus/tokenize_attributes"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.required_ruby_version = ">= 1.9.3"
|
17
|
+
spec.required_rubygems_version = ">= 2.0.0"
|
18
|
+
|
19
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
20
|
+
# delete this section to allow pushing this gem to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'activerecord', '>= 4.0.0'
|
34
|
+
spec.add_development_dependency 'rspec'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tokenize_attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandre Overtus
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Tokenize attributes in active record object.
|
56
|
+
email:
|
57
|
+
- a.overtus@live.be
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".readme"
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/tokenize_attributes.rb
|
69
|
+
- lib/tokenize_attributes/attribute.rb
|
70
|
+
- lib/tokenize_attributes/configuration.rb
|
71
|
+
- lib/tokenize_attributes/railtie.rb
|
72
|
+
- lib/tokenize_attributes/version.rb
|
73
|
+
- tokenize_attributes.gemspec
|
74
|
+
homepage: https://github.com/aovertus/tokenize_attributes
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.9.3
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 2.0.0
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.6.13
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Tokenize attributes in active record object.
|
99
|
+
test_files: []
|