lite-uxid 1.0.3 → 1.0.8
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 +4 -4
- data/.rubocop.yml +17 -3
- data/.travis.yml +1 -0
- data/CHANGELOG.md +29 -4
- data/Gemfile.lock +94 -77
- data/README.md +15 -14
- data/benchmarks/compare.rb +2 -2
- data/lib/generators/lite/uxid/install_generator.rb +1 -1
- data/lib/lite/uxid.rb +1 -1
- data/lib/lite/uxid/configuration.rb +14 -8
- data/lib/lite/uxid/{hash.rb → hashid.rb} +1 -1
- data/lib/lite/uxid/nanoid.rb +1 -10
- data/lib/lite/uxid/record/{hash.rb → hashid.rb} +4 -5
- data/lib/lite/uxid/record/nanoid.rb +8 -2
- data/lib/lite/uxid/record/ulid.rb +0 -1
- data/lib/lite/uxid/ulid.rb +1 -1
- data/lib/lite/uxid/version.rb +1 -1
- data/lite-uxid.gemspec +3 -1
- metadata +38 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 46a682a5b8665f23e50bcd330c9d9c8a83edf34bf944a478d6048ca5d500de22
|
|
4
|
+
data.tar.gz: cd7e879aa52bfddb016c0900826ae0bd321ea294f5671306ece55c94ab6a3fcc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f510611e353949ad0aa1ce52486c984378382bca15a08f082ab516679f120d121d0f39f6299e53d7685ded9c17062fd92263517e3b8394d7f2220a0d1ce51427
|
|
7
|
+
data.tar.gz: 79636eb6ed08cd6edc0219774fb5ffaa6895b249d6d9bea3520017480ec15f8c286ab3d1686bd74cbb988cdef88761cea79515d430acc95598c36a3e9db5da97
|
data/.rubocop.yml
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
require:
|
|
2
2
|
- rubocop-performance
|
|
3
|
+
- rubocop-rake
|
|
3
4
|
- rubocop-rspec
|
|
4
5
|
AllCops:
|
|
5
|
-
TargetRubyVersion: 2.
|
|
6
|
+
TargetRubyVersion: 2.7
|
|
7
|
+
NewCops: enable
|
|
6
8
|
DisplayCopNames: true
|
|
7
9
|
DisplayStyleGuide: true
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
Gemspec/RequiredRubyVersion:
|
|
11
|
+
Enabled: false
|
|
12
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
|
13
|
+
Enabled: true
|
|
10
14
|
Layout/EmptyLinesAroundBlockBody:
|
|
11
15
|
Exclude:
|
|
12
16
|
- 'spec/**/**/*'
|
|
@@ -14,6 +18,14 @@ Layout/EmptyLinesAroundClassBody:
|
|
|
14
18
|
EnforcedStyle: empty_lines_except_namespace
|
|
15
19
|
Layout/EmptyLinesAroundModuleBody:
|
|
16
20
|
EnforcedStyle: empty_lines_except_namespace
|
|
21
|
+
Layout/LineLength:
|
|
22
|
+
Max: 100
|
|
23
|
+
Layout/SpaceAroundMethodCallOperator:
|
|
24
|
+
Enabled: true
|
|
25
|
+
Lint/RaiseException:
|
|
26
|
+
Enabled: true
|
|
27
|
+
Lint/StructNewOverride:
|
|
28
|
+
Enabled: true
|
|
17
29
|
Metrics/BlockLength:
|
|
18
30
|
Exclude:
|
|
19
31
|
- 'spec/**/**/*'
|
|
@@ -24,3 +36,5 @@ Style/Documentation:
|
|
|
24
36
|
Enabled: false
|
|
25
37
|
Style/ExpandPathArguments:
|
|
26
38
|
Enabled: false
|
|
39
|
+
Style/SlicingWithRange:
|
|
40
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -6,21 +6,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.0.8] - 2021-05-07
|
|
10
|
+
### Changed
|
|
11
|
+
- Linter fixes
|
|
12
|
+
|
|
13
|
+
## [1.0.7] - 2019-08-26
|
|
14
|
+
### Added
|
|
15
|
+
- Added ruby 2.7 support
|
|
16
|
+
- Added prevention of Nanoid collision when using with active_record
|
|
17
|
+
### Changed
|
|
18
|
+
- Renamed Hash to Hashid
|
|
19
|
+
|
|
20
|
+
## [1.0.6] - 2019-08-26
|
|
21
|
+
### Changed
|
|
22
|
+
- Improved how configuration works
|
|
23
|
+
### Removed
|
|
24
|
+
- Remove active_record requirement that are already provided by Rails
|
|
25
|
+
|
|
26
|
+
## [1.0.5] - 2019-08-24
|
|
27
|
+
### Changed
|
|
28
|
+
- Improved how configuration works
|
|
29
|
+
|
|
30
|
+
## [1.0.4] - 2019-08-15
|
|
31
|
+
### Changed
|
|
32
|
+
- Underscore initializer file name
|
|
33
|
+
|
|
9
34
|
## [1.0.3] - 2019-07-31
|
|
10
35
|
### Added
|
|
11
36
|
- Added benchmarks
|
|
12
37
|
### Changed
|
|
13
38
|
- Changed instance method names to match class names
|
|
14
|
-
- Changed
|
|
15
|
-
- Changed
|
|
39
|
+
- Changed Nanoid encoder to be faster
|
|
40
|
+
- Changed Ulid encoder to be faster
|
|
16
41
|
|
|
17
42
|
## [1.0.2] - 2019-07-30
|
|
18
43
|
### Added
|
|
19
|
-
- Added
|
|
44
|
+
- Added Nanoid
|
|
20
45
|
|
|
21
46
|
## [1.0.1] - 2019-06-25
|
|
22
47
|
### Removed
|
|
23
|
-
- Remove unused
|
|
48
|
+
- Remove unused active_support dependency
|
|
24
49
|
|
|
25
50
|
## [1.0.0] - 2019-06-25
|
|
26
51
|
### Added
|
data/Gemfile.lock
CHANGED
|
@@ -1,120 +1,136 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lite-uxid (1.0.
|
|
4
|
+
lite-uxid (1.0.8)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
actionpack (
|
|
10
|
-
actionview (=
|
|
11
|
-
activesupport (=
|
|
12
|
-
rack (~> 2.0)
|
|
9
|
+
actionpack (6.1.3.2)
|
|
10
|
+
actionview (= 6.1.3.2)
|
|
11
|
+
activesupport (= 6.1.3.2)
|
|
12
|
+
rack (~> 2.0, >= 2.0.9)
|
|
13
13
|
rack-test (>= 0.6.3)
|
|
14
14
|
rails-dom-testing (~> 2.0)
|
|
15
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
|
16
|
-
actionview (
|
|
17
|
-
activesupport (=
|
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
16
|
+
actionview (6.1.3.2)
|
|
17
|
+
activesupport (= 6.1.3.2)
|
|
18
18
|
builder (~> 3.1)
|
|
19
19
|
erubi (~> 1.4)
|
|
20
20
|
rails-dom-testing (~> 2.0)
|
|
21
|
-
rails-html-sanitizer (~> 1.
|
|
22
|
-
activemodel (
|
|
23
|
-
activesupport (=
|
|
24
|
-
activerecord (
|
|
25
|
-
activemodel (=
|
|
26
|
-
activesupport (=
|
|
27
|
-
|
|
28
|
-
activesupport (5.2.3)
|
|
21
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
22
|
+
activemodel (6.1.3.2)
|
|
23
|
+
activesupport (= 6.1.3.2)
|
|
24
|
+
activerecord (6.1.3.2)
|
|
25
|
+
activemodel (= 6.1.3.2)
|
|
26
|
+
activesupport (= 6.1.3.2)
|
|
27
|
+
activesupport (6.1.3.2)
|
|
29
28
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
30
|
-
i18n (>=
|
|
31
|
-
minitest (
|
|
32
|
-
tzinfo (~>
|
|
33
|
-
|
|
34
|
-
ast (2.4.
|
|
35
|
-
builder (3.2.
|
|
29
|
+
i18n (>= 1.6, < 2)
|
|
30
|
+
minitest (>= 5.1)
|
|
31
|
+
tzinfo (~> 2.0)
|
|
32
|
+
zeitwerk (~> 2.3)
|
|
33
|
+
ast (2.4.2)
|
|
34
|
+
builder (3.2.4)
|
|
36
35
|
colorize (0.8.1)
|
|
37
|
-
concurrent-ruby (1.1.
|
|
38
|
-
crass (1.0.
|
|
39
|
-
database_cleaner (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
concurrent-ruby (1.1.8)
|
|
37
|
+
crass (1.0.6)
|
|
38
|
+
database_cleaner (2.0.1)
|
|
39
|
+
database_cleaner-active_record (~> 2.0.0)
|
|
40
|
+
database_cleaner-active_record (2.0.0)
|
|
41
|
+
activerecord (>= 5.a)
|
|
42
|
+
database_cleaner-core (~> 2.0.0)
|
|
43
|
+
database_cleaner-core (2.0.1)
|
|
44
|
+
diff-lcs (1.4.4)
|
|
45
|
+
erubi (1.10.0)
|
|
46
|
+
fasterer (0.9.0)
|
|
43
47
|
colorize (~> 0.7)
|
|
44
|
-
ruby_parser (>= 3.
|
|
48
|
+
ruby_parser (>= 3.14.1)
|
|
45
49
|
generator_spec (0.9.4)
|
|
46
50
|
activesupport (>= 3.0.0)
|
|
47
51
|
railties (>= 3.0.0)
|
|
48
|
-
i18n (1.
|
|
52
|
+
i18n (1.8.10)
|
|
49
53
|
concurrent-ruby (~> 1.0)
|
|
50
|
-
|
|
51
|
-
loofah (2.2.3)
|
|
54
|
+
loofah (2.9.1)
|
|
52
55
|
crass (~> 1.0.2)
|
|
53
56
|
nokogiri (>= 1.5.9)
|
|
54
|
-
method_source (0.
|
|
55
|
-
mini_portile2 (2.
|
|
56
|
-
minitest (5.
|
|
57
|
-
nokogiri (1.
|
|
58
|
-
mini_portile2 (~> 2.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
method_source (1.0.0)
|
|
58
|
+
mini_portile2 (2.5.1)
|
|
59
|
+
minitest (5.14.4)
|
|
60
|
+
nokogiri (1.11.3)
|
|
61
|
+
mini_portile2 (~> 2.5.0)
|
|
62
|
+
racc (~> 1.4)
|
|
63
|
+
parallel (1.20.1)
|
|
64
|
+
parser (3.0.1.1)
|
|
65
|
+
ast (~> 2.4.1)
|
|
66
|
+
racc (1.5.2)
|
|
67
|
+
rack (2.2.3)
|
|
63
68
|
rack-test (1.1.0)
|
|
64
69
|
rack (>= 1.0, < 3)
|
|
65
70
|
rails-dom-testing (2.0.3)
|
|
66
71
|
activesupport (>= 4.2.0)
|
|
67
72
|
nokogiri (>= 1.6)
|
|
68
|
-
rails-html-sanitizer (1.0
|
|
69
|
-
loofah (~> 2.
|
|
70
|
-
railties (
|
|
71
|
-
actionpack (=
|
|
72
|
-
activesupport (=
|
|
73
|
+
rails-html-sanitizer (1.3.0)
|
|
74
|
+
loofah (~> 2.3)
|
|
75
|
+
railties (6.1.3.2)
|
|
76
|
+
actionpack (= 6.1.3.2)
|
|
77
|
+
activesupport (= 6.1.3.2)
|
|
73
78
|
method_source
|
|
74
79
|
rake (>= 0.8.7)
|
|
75
|
-
thor (
|
|
80
|
+
thor (~> 1.0)
|
|
76
81
|
rainbow (3.0.0)
|
|
77
|
-
rake (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
rspec-
|
|
82
|
-
|
|
83
|
-
rspec-
|
|
84
|
-
rspec-
|
|
82
|
+
rake (13.0.3)
|
|
83
|
+
regexp_parser (2.1.1)
|
|
84
|
+
rexml (3.2.5)
|
|
85
|
+
rspec (3.10.0)
|
|
86
|
+
rspec-core (~> 3.10.0)
|
|
87
|
+
rspec-expectations (~> 3.10.0)
|
|
88
|
+
rspec-mocks (~> 3.10.0)
|
|
89
|
+
rspec-core (3.10.1)
|
|
90
|
+
rspec-support (~> 3.10.0)
|
|
91
|
+
rspec-expectations (3.10.1)
|
|
85
92
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
86
|
-
rspec-support (~> 3.
|
|
87
|
-
rspec-mocks (3.
|
|
93
|
+
rspec-support (~> 3.10.0)
|
|
94
|
+
rspec-mocks (3.10.2)
|
|
88
95
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
89
|
-
rspec-support (~> 3.
|
|
90
|
-
rspec-support (3.
|
|
91
|
-
rubocop (
|
|
92
|
-
jaro_winkler (~> 1.5.1)
|
|
96
|
+
rspec-support (~> 3.10.0)
|
|
97
|
+
rspec-support (3.10.2)
|
|
98
|
+
rubocop (1.14.0)
|
|
93
99
|
parallel (~> 1.10)
|
|
94
|
-
parser (>=
|
|
100
|
+
parser (>= 3.0.0.0)
|
|
95
101
|
rainbow (>= 2.2.2, < 4.0)
|
|
102
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
103
|
+
rexml
|
|
104
|
+
rubocop-ast (>= 1.5.0, < 2.0)
|
|
96
105
|
ruby-progressbar (~> 1.7)
|
|
97
|
-
unicode-display_width (>= 1.4.0, <
|
|
98
|
-
rubocop-
|
|
99
|
-
|
|
100
|
-
rubocop-
|
|
101
|
-
rubocop (>=
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
107
|
+
rubocop-ast (1.5.0)
|
|
108
|
+
parser (>= 3.0.1.1)
|
|
109
|
+
rubocop-performance (1.11.3)
|
|
110
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
111
|
+
rubocop-ast (>= 0.4.0)
|
|
112
|
+
rubocop-rake (0.5.1)
|
|
113
|
+
rubocop
|
|
114
|
+
rubocop-rspec (2.3.0)
|
|
115
|
+
rubocop (~> 1.0)
|
|
116
|
+
rubocop-ast (>= 1.1.0)
|
|
117
|
+
ruby-progressbar (1.11.0)
|
|
118
|
+
ruby_parser (3.15.1)
|
|
104
119
|
sexp_processor (~> 4.9)
|
|
105
|
-
sexp_processor (4.
|
|
106
|
-
sqlite3 (1.4.
|
|
107
|
-
thor (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
sexp_processor (4.15.2)
|
|
121
|
+
sqlite3 (1.4.2)
|
|
122
|
+
thor (1.1.0)
|
|
123
|
+
tzinfo (2.0.4)
|
|
124
|
+
concurrent-ruby (~> 1.0)
|
|
125
|
+
unicode-display_width (2.0.0)
|
|
126
|
+
zeitwerk (2.4.2)
|
|
112
127
|
|
|
113
128
|
PLATFORMS
|
|
114
129
|
ruby
|
|
115
130
|
|
|
116
131
|
DEPENDENCIES
|
|
117
132
|
activerecord
|
|
133
|
+
activesupport
|
|
118
134
|
bundler
|
|
119
135
|
database_cleaner
|
|
120
136
|
fasterer
|
|
@@ -124,8 +140,9 @@ DEPENDENCIES
|
|
|
124
140
|
rspec
|
|
125
141
|
rubocop
|
|
126
142
|
rubocop-performance
|
|
143
|
+
rubocop-rake
|
|
127
144
|
rubocop-rspec
|
|
128
145
|
sqlite3
|
|
129
146
|
|
|
130
147
|
BUNDLED WITH
|
|
131
|
-
2.
|
|
148
|
+
2.2.17
|
data/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](http://badge.fury.io/rb/lite-uxid)
|
|
4
4
|
[](https://travis-ci.org/drexed/lite-uxid)
|
|
5
5
|
|
|
6
|
-
Lite::Uxid is a library for generating or obfuscating Id's based on
|
|
6
|
+
Lite::Uxid is a library for generating or obfuscating Id's based on different patterns.
|
|
7
7
|
It's very useful to hide the number of resources in your database and protect against enumeration attacks.
|
|
8
8
|
|
|
9
9
|
**NOTE:** If you are coming from `ActiveUxid`, please read the [port](#port) section.
|
|
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
|
27
27
|
## Table of Contents
|
|
28
28
|
|
|
29
29
|
* [Configuration](#configuration)
|
|
30
|
-
* [
|
|
30
|
+
* [Hashid](#hashid)
|
|
31
31
|
* [NanoID](#nanoid)
|
|
32
32
|
* [ULID](#ulid)
|
|
33
33
|
* [ActiveRecord](#active_record)
|
|
@@ -37,7 +37,7 @@ Or install it yourself as:
|
|
|
37
37
|
## Configuration
|
|
38
38
|
|
|
39
39
|
`rails g lite:uxid:install` will generate the following file:
|
|
40
|
-
`../config/initalizers/
|
|
40
|
+
`../config/initalizers/lite_uxid.rb`
|
|
41
41
|
|
|
42
42
|
```ruby
|
|
43
43
|
Lite::Uxid.configure do |config|
|
|
@@ -47,13 +47,13 @@ Lite::Uxid.configure do |config|
|
|
|
47
47
|
end
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
##
|
|
50
|
+
## Hashid
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
Hashid's are reversible and is the most performant generator.
|
|
53
53
|
|
|
54
54
|
```ruby
|
|
55
|
-
Lite::Uxid::
|
|
56
|
-
Lite::Uxid::
|
|
55
|
+
Lite::Uxid::Hashid.encode(10) #=> 'q5D8inm0'
|
|
56
|
+
Lite::Uxid::Hashid.decode('q5D8inm0') #=> 10
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
## NanoID
|
|
@@ -80,7 +80,7 @@ Add the following attribute to all corresponding tables.
|
|
|
80
80
|
|
|
81
81
|
```ruby
|
|
82
82
|
# omitted
|
|
83
|
-
t.binary :uxid,
|
|
83
|
+
t.binary :uxid, index: { unique: true }
|
|
84
84
|
# omitted
|
|
85
85
|
```
|
|
86
86
|
|
|
@@ -90,7 +90,7 @@ All `nanoid` and `uxid` attributes will be automatically generated and applied w
|
|
|
90
90
|
|
|
91
91
|
```ruby
|
|
92
92
|
class User < ActiveRecord::Base
|
|
93
|
-
include Lite::Uxid::Record::
|
|
93
|
+
include Lite::Uxid::Record::Hashid
|
|
94
94
|
|
|
95
95
|
# - or -
|
|
96
96
|
|
|
@@ -104,19 +104,20 @@ end
|
|
|
104
104
|
|
|
105
105
|
**Usage**
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
Using one of the mixins above provides a handy method to find records by uxid.
|
|
108
108
|
|
|
109
109
|
```ruby
|
|
110
|
-
User.
|
|
111
|
-
User.
|
|
110
|
+
User.find_by_uxid('x123') #=> Find record by uxid
|
|
111
|
+
User.find_by_uxid!('x123') #=> Raises an ActiveRecord::RecordNotFound error if not found
|
|
112
112
|
|
|
113
|
+
# The following method is for Hashid based Uxid's.
|
|
113
114
|
user = User.new
|
|
114
|
-
user.
|
|
115
|
+
user.uxid_to_id #=> Decodes the records uxid to id (only for Hashid based Id's)
|
|
115
116
|
```
|
|
116
117
|
|
|
117
118
|
## Benchmarks
|
|
118
119
|
|
|
119
|
-
The classes ranked from fastest to slowest are `
|
|
120
|
+
The classes ranked from fastest to slowest are `Hashid`, `Nanoid`, and `Ulid`.
|
|
120
121
|
|
|
121
122
|
View how each compares by running the [benchmarks](https://github.com/drexed/lite-uxid/tree/master/benchmarks).
|
|
122
123
|
|
data/benchmarks/compare.rb
CHANGED
data/lib/lite/uxid.rb
CHANGED
|
@@ -15,16 +15,22 @@ module Lite
|
|
|
15
15
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
@configuration ||= Configuration.new
|
|
20
|
-
end
|
|
18
|
+
class << self
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
attr_writer :configuration
|
|
21
|
+
|
|
22
|
+
def configuration
|
|
23
|
+
@configuration ||= Configuration.new
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def configure
|
|
27
|
+
yield(configuration)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def reset_configuration!
|
|
31
|
+
@configuration = Configuration.new
|
|
32
|
+
end
|
|
25
33
|
|
|
26
|
-
def self.configure
|
|
27
|
-
yield(configuration)
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
end
|
data/lib/lite/uxid/nanoid.rb
CHANGED
|
@@ -14,16 +14,7 @@ module Lite
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def encode
|
|
17
|
-
|
|
18
|
-
len = encoding_length
|
|
19
|
-
chars = encoding_chars.split(str)
|
|
20
|
-
|
|
21
|
-
while len.positive?
|
|
22
|
-
str += chars.sample
|
|
23
|
-
len -= 1
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
str
|
|
17
|
+
encoding_chars.chars.sample(encoding_length).join
|
|
27
18
|
end
|
|
28
19
|
|
|
29
20
|
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'active_record'
|
|
4
3
|
require 'active_support'
|
|
5
4
|
|
|
6
5
|
module Lite
|
|
7
6
|
module Uxid
|
|
8
7
|
module Record
|
|
9
|
-
module
|
|
8
|
+
module Hashid
|
|
10
9
|
|
|
11
10
|
extend ActiveSupport::Concern
|
|
12
11
|
|
|
@@ -16,7 +15,7 @@ module Lite
|
|
|
16
15
|
|
|
17
16
|
class_methods do
|
|
18
17
|
def find_by_uxid(uxid)
|
|
19
|
-
decoded_id = Lite::Uxid::
|
|
18
|
+
decoded_id = Lite::Uxid::Hashid.decode(uxid)
|
|
20
19
|
find_by(id: decoded_id)
|
|
21
20
|
end
|
|
22
21
|
|
|
@@ -31,13 +30,13 @@ module Lite
|
|
|
31
30
|
def uxid_to_id
|
|
32
31
|
return unless respond_to?(:uxid)
|
|
33
32
|
|
|
34
|
-
Lite::Uxid::
|
|
33
|
+
Lite::Uxid::Hashid.decode(uxid)
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
private
|
|
38
37
|
|
|
39
38
|
def callback_generate_uxid!
|
|
40
|
-
hash = Lite::Uxid::
|
|
39
|
+
hash = Lite::Uxid::Hashid.encode(id)
|
|
41
40
|
update_column(:uxid, hash)
|
|
42
41
|
end
|
|
43
42
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'active_record'
|
|
4
3
|
require 'active_support'
|
|
5
4
|
|
|
6
5
|
module Lite
|
|
@@ -30,7 +29,14 @@ module Lite
|
|
|
30
29
|
private
|
|
31
30
|
|
|
32
31
|
def callback_generate_uxid!
|
|
33
|
-
|
|
32
|
+
random_nanoid = nil
|
|
33
|
+
|
|
34
|
+
loop do
|
|
35
|
+
random_nanoid = Lite::Uxid::Nanoid.encode
|
|
36
|
+
break unless self.class.exists?(uxid: random_nanoid)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
self.uxid = random_nanoid
|
|
34
40
|
end
|
|
35
41
|
|
|
36
42
|
end
|
data/lib/lite/uxid/ulid.rb
CHANGED
data/lib/lite/uxid/version.rb
CHANGED
data/lite-uxid.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.authors = ['Juan Gomez']
|
|
11
11
|
spec.email = %w[j.gomez@drexed.com]
|
|
12
12
|
|
|
13
|
-
spec.summary = "Generate or obfuscate
|
|
13
|
+
spec.summary = "Generate or obfuscate Id's using different patterns"
|
|
14
14
|
spec.homepage = 'http://drexed.github.io/lite-uxid'
|
|
15
15
|
spec.license = 'MIT'
|
|
16
16
|
|
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
|
|
|
38
38
|
spec.require_paths = %w[lib]
|
|
39
39
|
|
|
40
40
|
spec.add_development_dependency 'activerecord'
|
|
41
|
+
spec.add_development_dependency 'activesupport'
|
|
41
42
|
spec.add_development_dependency 'bundler'
|
|
42
43
|
spec.add_development_dependency 'database_cleaner'
|
|
43
44
|
spec.add_development_dependency 'fasterer'
|
|
@@ -46,6 +47,7 @@ Gem::Specification.new do |spec|
|
|
|
46
47
|
spec.add_development_dependency 'rspec'
|
|
47
48
|
spec.add_development_dependency 'rubocop'
|
|
48
49
|
spec.add_development_dependency 'rubocop-performance'
|
|
50
|
+
spec.add_development_dependency 'rubocop-rake'
|
|
49
51
|
spec.add_development_dependency 'rubocop-rspec'
|
|
50
52
|
spec.add_development_dependency 'sqlite3'
|
|
51
53
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lite-uxid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juan Gomez
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activesupport
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: bundler
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -136,6 +150,20 @@ dependencies:
|
|
|
136
150
|
- - ">="
|
|
137
151
|
- !ruby/object:Gem::Version
|
|
138
152
|
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: rubocop-rake
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ">="
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '0'
|
|
139
167
|
- !ruby/object:Gem::Dependency
|
|
140
168
|
name: rubocop-rspec
|
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -164,7 +192,7 @@ dependencies:
|
|
|
164
192
|
- - ">="
|
|
165
193
|
- !ruby/object:Gem::Version
|
|
166
194
|
version: '0'
|
|
167
|
-
description:
|
|
195
|
+
description:
|
|
168
196
|
email:
|
|
169
197
|
- j.gomez@drexed.com
|
|
170
198
|
executables: []
|
|
@@ -192,9 +220,9 @@ files:
|
|
|
192
220
|
- lib/lite/uxid.rb
|
|
193
221
|
- lib/lite/uxid/base.rb
|
|
194
222
|
- lib/lite/uxid/configuration.rb
|
|
195
|
-
- lib/lite/uxid/
|
|
223
|
+
- lib/lite/uxid/hashid.rb
|
|
196
224
|
- lib/lite/uxid/nanoid.rb
|
|
197
|
-
- lib/lite/uxid/record/
|
|
225
|
+
- lib/lite/uxid/record/hashid.rb
|
|
198
226
|
- lib/lite/uxid/record/nanoid.rb
|
|
199
227
|
- lib/lite/uxid/record/ulid.rb
|
|
200
228
|
- lib/lite/uxid/ulid.rb
|
|
@@ -204,7 +232,7 @@ homepage: http://drexed.github.io/lite-uxid
|
|
|
204
232
|
licenses:
|
|
205
233
|
- MIT
|
|
206
234
|
metadata: {}
|
|
207
|
-
post_install_message:
|
|
235
|
+
post_install_message:
|
|
208
236
|
rdoc_options: []
|
|
209
237
|
require_paths:
|
|
210
238
|
- lib
|
|
@@ -219,8 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
219
247
|
- !ruby/object:Gem::Version
|
|
220
248
|
version: '0'
|
|
221
249
|
requirements: []
|
|
222
|
-
rubygems_version: 3.
|
|
223
|
-
signing_key:
|
|
250
|
+
rubygems_version: 3.2.17
|
|
251
|
+
signing_key:
|
|
224
252
|
specification_version: 4
|
|
225
|
-
summary: Generate or obfuscate
|
|
253
|
+
summary: Generate or obfuscate Id's using different patterns
|
|
226
254
|
test_files: []
|