encoded_id-rails 1.0.0.beta1 → 1.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +14 -0
- data/CHANGELOG.md +5 -1
- data/README.md +58 -27
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_6.1.gemfile +16 -0
- data/gemfiles/rails_6.1.gemfile.lock +130 -0
- data/gemfiles/rails_7.0.gemfile +10 -5
- data/gemfiles/rails_7.0.gemfile.lock +128 -0
- data/gemfiles/rails_7.1.gemfile +16 -0
- data/gemfiles/rails_7.1.gemfile.lock +140 -0
- data/lib/encoded_id/rails/coder.rb +1 -1
- data/lib/encoded_id/rails/configuration.rb +30 -9
- data/lib/encoded_id/rails/encoder_methods.rb +3 -2
- data/lib/encoded_id/rails/version.rb +1 -1
- data/lib/generators/encoded_id/rails/templates/encoded_id.rb +26 -0
- metadata +28 -8
- data/gemfiles/rails_6.0.gemfile +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a38e6af88bf9343e2e4d22a82eb4c4d87766e962f3a8d330bf6aad1ad374639
|
4
|
+
data.tar.gz: 3ea6b28d604d3f728da545d324f50b12845f2feb9b7ed83c32349e002cdb6c93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b03bc14efe460f8f479f109d32a4197c88cc85b72d87b7aa348e40057c4ae540728f5f3c383b943460ebbfdcfdd7e3173c363dbb423026386331fe17ea7e50e8
|
7
|
+
data.tar.gz: 5a6f16dc29c1c43450f278e08b7c82e597e13a70b4ea5183cbcc97d690307c6b847b5fef8cd594cb0f1396aca685beac78a8c427826b2003a1b2820b319793a3
|
data/Appraisals
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
appraise "rails-6.1" do
|
2
|
+
gem "activesupport", "~> 6.1.7", ">= 6.1.0"
|
3
|
+
gem "activerecord", "~> 6.1.7", ">= 6.1.0"
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "rails-7.0" do
|
7
|
+
gem "activesupport", "~> 7.0.4"
|
8
|
+
gem "activerecord", "~> 7.0.4"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "rails-7.1" do
|
12
|
+
gem "activesupport", "~> 7.1"
|
13
|
+
gem "activerecord", "~> 7.1"
|
14
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [1.0.0
|
3
|
+
## [1.0.0] - (in beta)
|
4
4
|
|
5
5
|
### Breaking changes
|
6
6
|
|
7
|
+
- Ruby 2.7.x support dropped. The minimum supported Ruby version is now 3.0.0.
|
7
8
|
- `#encoded_id` now defaults to returning an 'annotated' ID, one in which a prefix is added to the encoded ID to indicate
|
8
9
|
the 'type' of the record the ID represents. This can be disabled. IDs generated by older versions of this gem will
|
9
10
|
decode correctly. But not that IDs generated by this version onwards will not decode correctly by older versions of this
|
@@ -22,6 +23,9 @@
|
|
22
23
|
- `.find_all_by_encoded_id!` like `.find_all_by_encoded_id` but raises an `ActiveRecord::RecordNotFound` exception if
|
23
24
|
*any* of the records are not found.
|
24
25
|
|
26
|
+
### Fixed
|
27
|
+
|
28
|
+
- `#decode_encoded_id` now raises if the encoded ID is not a string.
|
25
29
|
|
26
30
|
## [0.6.2] - 2023-02-09
|
27
31
|
|
data/README.md
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
# EncodedId::Rails (`encoded_id-rails`)
|
2
2
|
|
3
|
-
[EncodedId](https://github.com/stevegeek/encoded_id)
|
3
|
+
`EncodedId::Rails` lets you turn numeric or hex **IDs into reversible and human friendly obfuscated strings**. The gem brings [EncodedId](https://github.com/stevegeek/encoded_id) to Rails and `ActiveRecord` models.
|
4
4
|
|
5
|
-
|
5
|
+
You can use it in routes for example, to go from something like `/users/725` to `/users/bob-smith--usr_p5w9-z27j` with miminal effort.
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
Under the hood it uses hashIds, but it offers more features.
|
10
|
+
|
11
|
+
- 🔄 encoded IDs are reversible (see [`encoded_id`](https://github.com/stevegeek/encoded_id))
|
12
|
+
- 💅 supports slugged IDs (eg `my-cool-product-name--p5w9-z27j`) that are URL friendly (assuming your alphabet is too)
|
13
|
+
- 🔖 supports annotated IDs to help identify the model the encoded ID belongs to (eg for a `User` the encoded ID might be `user_p5w9-z27j`)
|
14
|
+
- 👓 encoded string can be split into groups of letters to improve human-readability (eg `abcd-efgh`)
|
15
|
+
- 👥 supports multiple IDs encoded in one encoded string (eg imagine the encoded ID `7aq60zqw` might decode to two IDs `[78, 45]`)
|
16
|
+
- 🔡 supports custom alphabets for the encoded string (at least 16 characters needed)
|
17
|
+
- by default uses a variation of the Crockford reduced character set (https://www.crockford.com/base32.html)
|
18
|
+
- easily confused characters (eg i and j, 0 and O, 1 and I etc) are mapped to counterpart characters, to
|
19
|
+
help avoid common readability mistakes when reading/sharing
|
20
|
+
- build in profanity limitation
|
21
|
+
|
22
|
+
The gem provides:
|
23
|
+
|
24
|
+
- methods to mixin to ActiveRecord models which will allow you to encode and decode IDs, and find
|
25
|
+
or query by encoded IDs
|
26
|
+
- sensible defaults to allow you to get started out of the box
|
6
27
|
|
7
28
|
```ruby
|
8
29
|
class User < ApplicationRecord
|
@@ -34,43 +55,25 @@ user == User.find_by_encoded_id("bob-smith--usr_p5w9-z27j") # => true
|
|
34
55
|
users = User.find_all_by_encoded_id("7aq60zqw") # => [#<User id: 78>, #<User id: 45>]
|
35
56
|
```
|
36
57
|
|
37
|
-
|
38
|
-
|
39
|
-
- encoded IDs are reversible (see [`encoded_id`](https://github.com/stevegeek/encoded_id))
|
40
|
-
- supports slugged IDs (eg `my-cool-product-name--p5w9-z27j`) that are URL friendly (assuming your alphabet is too)
|
41
|
-
- supports annotated IDs to help identify the model the encoded ID belongs to (eg for a `User` the encoded ID might be `user_p5w9-z27j`)
|
42
|
-
- encoded string can be split into groups of letters to improve human-readability (eg `abcd-efgh`)
|
43
|
-
- supports multiple IDs encoded in one encoded string (eg imagine the encoded ID `7aq60zqw` might decode to two IDs `[78, 45]`)
|
44
|
-
- supports custom alphabets for the encoded string (at least 16 characters needed)
|
45
|
-
- by default uses a variation of the Crockford reduced character set (https://www.crockford.com/base32.html)
|
46
|
-
- easily confused characters (eg i and j, 0 and O, 1 and I etc) are mapped to counterpart characters, to
|
47
|
-
help avoid common readability mistakes when reading/sharing
|
48
|
-
- build in profanity limitation
|
49
|
-
|
50
|
-
The gem provides:
|
51
|
-
|
52
|
-
- methods to mixin to ActiveRecord models which will allow you to encode and decode IDs, and find
|
53
|
-
or query by encoded IDs
|
54
|
-
- sensible defaults to allow you to get started out of the box
|
55
|
-
|
56
|
-
### Coming in future (?)
|
57
|
-
|
58
|
-
- support for UUIDs for IDs (which will be encoded as an array of integers)
|
59
|
-
|
60
|
-
# Why this gem?
|
58
|
+
## Why this gem?
|
61
59
|
|
62
60
|
With this gem you can easily obfuscate your IDs in your URLs, and still be able to find records by using
|
63
61
|
the encoded IDs. The encoded IDs are meant to be somewhat human friendly, to make communication easier
|
64
62
|
when sharing encoded IDs with other people.
|
65
63
|
|
66
64
|
* Hashids are reversible, no need to persist the generated Id
|
67
|
-
* we don't override any AR methods. `encoded_id`s are intentionally not interchangeable with normal record `id`s
|
65
|
+
* we don't override any AR methods. `encoded_id`s are intentionally **not interchangeable** with normal record `id`s
|
68
66
|
(ie you can't use `.find` to find by encoded ID or record ID, you must be explicit)
|
69
67
|
* we support slugged IDs (eg `my-amazing-product--p5w9-z27j`)
|
70
68
|
* we support multiple model IDs encoded in one `EncodedId` (eg `7aq6-0zqw` might decode to `[78, 45]`)
|
71
69
|
* the gem is configurable
|
72
70
|
* encoded IDs can be stable across environments, or not (you can set the salt to different values per environment)
|
73
71
|
|
72
|
+
|
73
|
+
## Coming in future (?)
|
74
|
+
|
75
|
+
- support for UUIDs for IDs (which will be encoded as an array of integers)
|
76
|
+
|
74
77
|
## Installation
|
75
78
|
|
76
79
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -360,6 +363,34 @@ end
|
|
360
363
|
|
361
364
|
However, I recommend you only use it on the models that need it.
|
362
365
|
|
366
|
+
## Example usage for a route and controller
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
# Route
|
370
|
+
resources :users, param: :encoded_id, only: [:show]
|
371
|
+
```
|
372
|
+
|
373
|
+
```ruby
|
374
|
+
# Model
|
375
|
+
class User < ApplicationRecord
|
376
|
+
include EncodedId::Model
|
377
|
+
include EncodedId::PathParam
|
378
|
+
end
|
379
|
+
```
|
380
|
+
|
381
|
+
```ruby
|
382
|
+
# Controller
|
383
|
+
class UsersController < ApplicationController
|
384
|
+
def show
|
385
|
+
@user = User.find_by_encoded_id!(params[:encoded_id])
|
386
|
+
end
|
387
|
+
end
|
388
|
+
```
|
389
|
+
|
390
|
+
```erb
|
391
|
+
<%= link_to "User", user_path %>
|
392
|
+
```
|
393
|
+
|
363
394
|
## Development
|
364
395
|
|
365
396
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 6.1.7", ">= 6.1.0"
|
6
|
+
gem "activerecord", "~> 6.1.7", ">= 6.1.0"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "rake", "~> 13.0"
|
10
|
+
gem "minitest", "~> 5.0"
|
11
|
+
gem "standard", "~> 1.30"
|
12
|
+
gem "steep", "~> 1.5"
|
13
|
+
gem "sqlite3", "~> 1.5"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -0,0 +1,130 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
encoded_id-rails (1.0.0.beta2)
|
5
|
+
activerecord (>= 6.0, < 8.0)
|
6
|
+
activesupport (>= 6.0, < 8.0)
|
7
|
+
encoded_id (~> 1.0.0.rc4)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
abbrev (0.1.2)
|
13
|
+
activemodel (6.1.7.7)
|
14
|
+
activesupport (= 6.1.7.7)
|
15
|
+
activerecord (6.1.7.7)
|
16
|
+
activemodel (= 6.1.7.7)
|
17
|
+
activesupport (= 6.1.7.7)
|
18
|
+
activesupport (6.1.7.7)
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
|
+
i18n (>= 1.6, < 2)
|
21
|
+
minitest (>= 5.1)
|
22
|
+
tzinfo (~> 2.0)
|
23
|
+
zeitwerk (~> 2.3)
|
24
|
+
appraisal (2.5.0)
|
25
|
+
bundler
|
26
|
+
rake
|
27
|
+
thor (>= 0.14.0)
|
28
|
+
ast (2.4.2)
|
29
|
+
concurrent-ruby (1.2.3)
|
30
|
+
csv (3.3.0)
|
31
|
+
encoded_id (1.0.0.rc4)
|
32
|
+
hashids (~> 1.0)
|
33
|
+
ffi (1.16.3)
|
34
|
+
fileutils (1.7.2)
|
35
|
+
hashids (1.0.6)
|
36
|
+
i18n (1.14.4)
|
37
|
+
concurrent-ruby (~> 1.0)
|
38
|
+
json (2.7.2)
|
39
|
+
language_server-protocol (3.17.0.3)
|
40
|
+
lint_roller (1.1.0)
|
41
|
+
listen (3.9.0)
|
42
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
43
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
44
|
+
logger (1.6.0)
|
45
|
+
minitest (5.22.3)
|
46
|
+
parallel (1.24.0)
|
47
|
+
parser (3.3.1.0)
|
48
|
+
ast (~> 2.4.1)
|
49
|
+
racc
|
50
|
+
racc (1.7.3)
|
51
|
+
rainbow (3.1.1)
|
52
|
+
rake (13.2.1)
|
53
|
+
rb-fsevent (0.11.2)
|
54
|
+
rb-inotify (0.10.1)
|
55
|
+
ffi (~> 1.0)
|
56
|
+
rbs (3.4.4)
|
57
|
+
abbrev
|
58
|
+
regexp_parser (2.9.0)
|
59
|
+
rexml (3.2.6)
|
60
|
+
rubocop (1.62.1)
|
61
|
+
json (~> 2.3)
|
62
|
+
language_server-protocol (>= 3.17.0)
|
63
|
+
parallel (~> 1.10)
|
64
|
+
parser (>= 3.3.0.2)
|
65
|
+
rainbow (>= 2.2.2, < 4.0)
|
66
|
+
regexp_parser (>= 1.8, < 3.0)
|
67
|
+
rexml (>= 3.2.5, < 4.0)
|
68
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
69
|
+
ruby-progressbar (~> 1.7)
|
70
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
71
|
+
rubocop-ast (1.31.3)
|
72
|
+
parser (>= 3.3.1.0)
|
73
|
+
rubocop-performance (1.20.2)
|
74
|
+
rubocop (>= 1.48.1, < 2.0)
|
75
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
76
|
+
ruby-progressbar (1.13.0)
|
77
|
+
securerandom (0.3.1)
|
78
|
+
sqlite3 (1.7.3-arm64-darwin)
|
79
|
+
standard (1.35.1)
|
80
|
+
language_server-protocol (~> 3.17.0.2)
|
81
|
+
lint_roller (~> 1.0)
|
82
|
+
rubocop (~> 1.62.0)
|
83
|
+
standard-custom (~> 1.0.0)
|
84
|
+
standard-performance (~> 1.3)
|
85
|
+
standard-custom (1.0.2)
|
86
|
+
lint_roller (~> 1.0)
|
87
|
+
rubocop (~> 1.50)
|
88
|
+
standard-performance (1.3.1)
|
89
|
+
lint_roller (~> 1.1)
|
90
|
+
rubocop-performance (~> 1.20.2)
|
91
|
+
steep (1.6.0)
|
92
|
+
activesupport (>= 5.1)
|
93
|
+
concurrent-ruby (>= 1.1.10)
|
94
|
+
csv (>= 3.0.9)
|
95
|
+
fileutils (>= 1.1.0)
|
96
|
+
json (>= 2.1.0)
|
97
|
+
language_server-protocol (>= 3.15, < 4.0)
|
98
|
+
listen (~> 3.0)
|
99
|
+
logger (>= 1.3.0)
|
100
|
+
parser (>= 3.1)
|
101
|
+
rainbow (>= 2.2.2, < 4.0)
|
102
|
+
rbs (>= 3.1.0)
|
103
|
+
securerandom (>= 0.1)
|
104
|
+
strscan (>= 1.0.0)
|
105
|
+
terminal-table (>= 2, < 4)
|
106
|
+
strscan (3.1.0)
|
107
|
+
terminal-table (3.0.2)
|
108
|
+
unicode-display_width (>= 1.1.1, < 3)
|
109
|
+
thor (1.3.1)
|
110
|
+
tzinfo (2.0.6)
|
111
|
+
concurrent-ruby (~> 1.0)
|
112
|
+
unicode-display_width (2.5.0)
|
113
|
+
zeitwerk (2.6.13)
|
114
|
+
|
115
|
+
PLATFORMS
|
116
|
+
arm64-darwin-23
|
117
|
+
|
118
|
+
DEPENDENCIES
|
119
|
+
activerecord (~> 6.1.7, >= 6.1.0)
|
120
|
+
activesupport (~> 6.1.7, >= 6.1.0)
|
121
|
+
appraisal
|
122
|
+
encoded_id-rails!
|
123
|
+
minitest (~> 5.0)
|
124
|
+
rake (~> 13.0)
|
125
|
+
sqlite3 (~> 1.5)
|
126
|
+
standard (~> 1.30)
|
127
|
+
steep (~> 1.5)
|
128
|
+
|
129
|
+
BUNDLED WITH
|
130
|
+
2.3.26
|
data/gemfiles/rails_7.0.gemfile
CHANGED
@@ -1,11 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
gem "sqlite3"
|
4
5
|
gem "activesupport", "~> 7.0.4"
|
5
6
|
gem "activerecord", "~> 7.0.4"
|
6
|
-
|
7
|
-
|
8
|
-
gem "
|
9
|
-
gem "
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "rake", "~> 13.0"
|
10
|
+
gem "minitest", "~> 5.0"
|
11
|
+
gem "standard", "~> 1.30"
|
12
|
+
gem "steep", "~> 1.5"
|
13
|
+
gem "sqlite3", "~> 1.5"
|
14
|
+
end
|
10
15
|
|
11
16
|
gemspec path: "../"
|
@@ -0,0 +1,128 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
encoded_id-rails (1.0.0.beta2)
|
5
|
+
activerecord (>= 6.0, < 8.0)
|
6
|
+
activesupport (>= 6.0, < 8.0)
|
7
|
+
encoded_id (~> 1.0.0.rc4)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
abbrev (0.1.2)
|
13
|
+
activemodel (7.0.8.1)
|
14
|
+
activesupport (= 7.0.8.1)
|
15
|
+
activerecord (7.0.8.1)
|
16
|
+
activemodel (= 7.0.8.1)
|
17
|
+
activesupport (= 7.0.8.1)
|
18
|
+
activesupport (7.0.8.1)
|
19
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
|
+
i18n (>= 1.6, < 2)
|
21
|
+
minitest (>= 5.1)
|
22
|
+
tzinfo (~> 2.0)
|
23
|
+
appraisal (2.5.0)
|
24
|
+
bundler
|
25
|
+
rake
|
26
|
+
thor (>= 0.14.0)
|
27
|
+
ast (2.4.2)
|
28
|
+
concurrent-ruby (1.2.3)
|
29
|
+
csv (3.3.0)
|
30
|
+
encoded_id (1.0.0.rc4)
|
31
|
+
hashids (~> 1.0)
|
32
|
+
ffi (1.16.3)
|
33
|
+
fileutils (1.7.2)
|
34
|
+
hashids (1.0.6)
|
35
|
+
i18n (1.14.4)
|
36
|
+
concurrent-ruby (~> 1.0)
|
37
|
+
json (2.7.2)
|
38
|
+
language_server-protocol (3.17.0.3)
|
39
|
+
lint_roller (1.1.0)
|
40
|
+
listen (3.9.0)
|
41
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
42
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
43
|
+
logger (1.6.0)
|
44
|
+
minitest (5.22.3)
|
45
|
+
parallel (1.24.0)
|
46
|
+
parser (3.3.1.0)
|
47
|
+
ast (~> 2.4.1)
|
48
|
+
racc
|
49
|
+
racc (1.7.3)
|
50
|
+
rainbow (3.1.1)
|
51
|
+
rake (13.2.1)
|
52
|
+
rb-fsevent (0.11.2)
|
53
|
+
rb-inotify (0.10.1)
|
54
|
+
ffi (~> 1.0)
|
55
|
+
rbs (3.4.4)
|
56
|
+
abbrev
|
57
|
+
regexp_parser (2.9.0)
|
58
|
+
rexml (3.2.6)
|
59
|
+
rubocop (1.62.1)
|
60
|
+
json (~> 2.3)
|
61
|
+
language_server-protocol (>= 3.17.0)
|
62
|
+
parallel (~> 1.10)
|
63
|
+
parser (>= 3.3.0.2)
|
64
|
+
rainbow (>= 2.2.2, < 4.0)
|
65
|
+
regexp_parser (>= 1.8, < 3.0)
|
66
|
+
rexml (>= 3.2.5, < 4.0)
|
67
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
68
|
+
ruby-progressbar (~> 1.7)
|
69
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
70
|
+
rubocop-ast (1.31.3)
|
71
|
+
parser (>= 3.3.1.0)
|
72
|
+
rubocop-performance (1.20.2)
|
73
|
+
rubocop (>= 1.48.1, < 2.0)
|
74
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
75
|
+
ruby-progressbar (1.13.0)
|
76
|
+
securerandom (0.3.1)
|
77
|
+
sqlite3 (1.7.3-arm64-darwin)
|
78
|
+
standard (1.35.1)
|
79
|
+
language_server-protocol (~> 3.17.0.2)
|
80
|
+
lint_roller (~> 1.0)
|
81
|
+
rubocop (~> 1.62.0)
|
82
|
+
standard-custom (~> 1.0.0)
|
83
|
+
standard-performance (~> 1.3)
|
84
|
+
standard-custom (1.0.2)
|
85
|
+
lint_roller (~> 1.0)
|
86
|
+
rubocop (~> 1.50)
|
87
|
+
standard-performance (1.3.1)
|
88
|
+
lint_roller (~> 1.1)
|
89
|
+
rubocop-performance (~> 1.20.2)
|
90
|
+
steep (1.6.0)
|
91
|
+
activesupport (>= 5.1)
|
92
|
+
concurrent-ruby (>= 1.1.10)
|
93
|
+
csv (>= 3.0.9)
|
94
|
+
fileutils (>= 1.1.0)
|
95
|
+
json (>= 2.1.0)
|
96
|
+
language_server-protocol (>= 3.15, < 4.0)
|
97
|
+
listen (~> 3.0)
|
98
|
+
logger (>= 1.3.0)
|
99
|
+
parser (>= 3.1)
|
100
|
+
rainbow (>= 2.2.2, < 4.0)
|
101
|
+
rbs (>= 3.1.0)
|
102
|
+
securerandom (>= 0.1)
|
103
|
+
strscan (>= 1.0.0)
|
104
|
+
terminal-table (>= 2, < 4)
|
105
|
+
strscan (3.1.0)
|
106
|
+
terminal-table (3.0.2)
|
107
|
+
unicode-display_width (>= 1.1.1, < 3)
|
108
|
+
thor (1.3.1)
|
109
|
+
tzinfo (2.0.6)
|
110
|
+
concurrent-ruby (~> 1.0)
|
111
|
+
unicode-display_width (2.5.0)
|
112
|
+
|
113
|
+
PLATFORMS
|
114
|
+
arm64-darwin-23
|
115
|
+
|
116
|
+
DEPENDENCIES
|
117
|
+
activerecord (~> 7.0.4)
|
118
|
+
activesupport (~> 7.0.4)
|
119
|
+
appraisal
|
120
|
+
encoded_id-rails!
|
121
|
+
minitest (~> 5.0)
|
122
|
+
rake (~> 13.0)
|
123
|
+
sqlite3 (~> 1.5)
|
124
|
+
standard (~> 1.30)
|
125
|
+
steep (~> 1.5)
|
126
|
+
|
127
|
+
BUNDLED WITH
|
128
|
+
2.3.26
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 7.1"
|
6
|
+
gem "activerecord", "~> 7.1"
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "rake", "~> 13.0"
|
10
|
+
gem "minitest", "~> 5.0"
|
11
|
+
gem "standard", "~> 1.30"
|
12
|
+
gem "steep", "~> 1.5"
|
13
|
+
gem "sqlite3", "~> 1.5"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
@@ -0,0 +1,140 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
encoded_id-rails (1.0.0.beta2)
|
5
|
+
activerecord (>= 6.0, < 8.0)
|
6
|
+
activesupport (>= 6.0, < 8.0)
|
7
|
+
encoded_id (~> 1.0.0.rc4)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
abbrev (0.1.2)
|
13
|
+
activemodel (7.1.3.2)
|
14
|
+
activesupport (= 7.1.3.2)
|
15
|
+
activerecord (7.1.3.2)
|
16
|
+
activemodel (= 7.1.3.2)
|
17
|
+
activesupport (= 7.1.3.2)
|
18
|
+
timeout (>= 0.4.0)
|
19
|
+
activesupport (7.1.3.2)
|
20
|
+
base64
|
21
|
+
bigdecimal
|
22
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
|
+
connection_pool (>= 2.2.5)
|
24
|
+
drb
|
25
|
+
i18n (>= 1.6, < 2)
|
26
|
+
minitest (>= 5.1)
|
27
|
+
mutex_m
|
28
|
+
tzinfo (~> 2.0)
|
29
|
+
appraisal (2.5.0)
|
30
|
+
bundler
|
31
|
+
rake
|
32
|
+
thor (>= 0.14.0)
|
33
|
+
ast (2.4.2)
|
34
|
+
base64 (0.2.0)
|
35
|
+
bigdecimal (3.1.7)
|
36
|
+
concurrent-ruby (1.2.3)
|
37
|
+
connection_pool (2.4.1)
|
38
|
+
csv (3.3.0)
|
39
|
+
drb (2.2.1)
|
40
|
+
encoded_id (1.0.0.rc4)
|
41
|
+
hashids (~> 1.0)
|
42
|
+
ffi (1.16.3)
|
43
|
+
fileutils (1.7.2)
|
44
|
+
hashids (1.0.6)
|
45
|
+
i18n (1.14.4)
|
46
|
+
concurrent-ruby (~> 1.0)
|
47
|
+
json (2.7.2)
|
48
|
+
language_server-protocol (3.17.0.3)
|
49
|
+
lint_roller (1.1.0)
|
50
|
+
listen (3.9.0)
|
51
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
52
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
53
|
+
logger (1.6.0)
|
54
|
+
minitest (5.22.3)
|
55
|
+
mutex_m (0.2.0)
|
56
|
+
parallel (1.24.0)
|
57
|
+
parser (3.3.1.0)
|
58
|
+
ast (~> 2.4.1)
|
59
|
+
racc
|
60
|
+
racc (1.7.3)
|
61
|
+
rainbow (3.1.1)
|
62
|
+
rake (13.2.1)
|
63
|
+
rb-fsevent (0.11.2)
|
64
|
+
rb-inotify (0.10.1)
|
65
|
+
ffi (~> 1.0)
|
66
|
+
rbs (3.4.4)
|
67
|
+
abbrev
|
68
|
+
regexp_parser (2.9.0)
|
69
|
+
rexml (3.2.6)
|
70
|
+
rubocop (1.62.1)
|
71
|
+
json (~> 2.3)
|
72
|
+
language_server-protocol (>= 3.17.0)
|
73
|
+
parallel (~> 1.10)
|
74
|
+
parser (>= 3.3.0.2)
|
75
|
+
rainbow (>= 2.2.2, < 4.0)
|
76
|
+
regexp_parser (>= 1.8, < 3.0)
|
77
|
+
rexml (>= 3.2.5, < 4.0)
|
78
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
79
|
+
ruby-progressbar (~> 1.7)
|
80
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
81
|
+
rubocop-ast (1.31.3)
|
82
|
+
parser (>= 3.3.1.0)
|
83
|
+
rubocop-performance (1.20.2)
|
84
|
+
rubocop (>= 1.48.1, < 2.0)
|
85
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
86
|
+
ruby-progressbar (1.13.0)
|
87
|
+
securerandom (0.3.1)
|
88
|
+
sqlite3 (1.7.3-arm64-darwin)
|
89
|
+
standard (1.35.1)
|
90
|
+
language_server-protocol (~> 3.17.0.2)
|
91
|
+
lint_roller (~> 1.0)
|
92
|
+
rubocop (~> 1.62.0)
|
93
|
+
standard-custom (~> 1.0.0)
|
94
|
+
standard-performance (~> 1.3)
|
95
|
+
standard-custom (1.0.2)
|
96
|
+
lint_roller (~> 1.0)
|
97
|
+
rubocop (~> 1.50)
|
98
|
+
standard-performance (1.3.1)
|
99
|
+
lint_roller (~> 1.1)
|
100
|
+
rubocop-performance (~> 1.20.2)
|
101
|
+
steep (1.6.0)
|
102
|
+
activesupport (>= 5.1)
|
103
|
+
concurrent-ruby (>= 1.1.10)
|
104
|
+
csv (>= 3.0.9)
|
105
|
+
fileutils (>= 1.1.0)
|
106
|
+
json (>= 2.1.0)
|
107
|
+
language_server-protocol (>= 3.15, < 4.0)
|
108
|
+
listen (~> 3.0)
|
109
|
+
logger (>= 1.3.0)
|
110
|
+
parser (>= 3.1)
|
111
|
+
rainbow (>= 2.2.2, < 4.0)
|
112
|
+
rbs (>= 3.1.0)
|
113
|
+
securerandom (>= 0.1)
|
114
|
+
strscan (>= 1.0.0)
|
115
|
+
terminal-table (>= 2, < 4)
|
116
|
+
strscan (3.1.0)
|
117
|
+
terminal-table (3.0.2)
|
118
|
+
unicode-display_width (>= 1.1.1, < 3)
|
119
|
+
thor (1.3.1)
|
120
|
+
timeout (0.4.1)
|
121
|
+
tzinfo (2.0.6)
|
122
|
+
concurrent-ruby (~> 1.0)
|
123
|
+
unicode-display_width (2.5.0)
|
124
|
+
|
125
|
+
PLATFORMS
|
126
|
+
arm64-darwin-23
|
127
|
+
|
128
|
+
DEPENDENCIES
|
129
|
+
activerecord (~> 7.1)
|
130
|
+
activesupport (~> 7.1)
|
131
|
+
appraisal
|
132
|
+
encoded_id-rails!
|
133
|
+
minitest (~> 5.0)
|
134
|
+
rake (~> 13.0)
|
135
|
+
sqlite3 (~> 1.5)
|
136
|
+
standard (~> 1.30)
|
137
|
+
steep (~> 1.5)
|
138
|
+
|
139
|
+
BUNDLED WITH
|
140
|
+
2.3.26
|
@@ -4,15 +4,9 @@ module EncodedId
|
|
4
4
|
module Rails
|
5
5
|
# Configuration class for initializer
|
6
6
|
class Configuration
|
7
|
-
attr_accessor :salt,
|
8
|
-
|
9
|
-
|
10
|
-
:alphabet,
|
11
|
-
:id_length,
|
12
|
-
:slug_value_method_name,
|
13
|
-
:slugged_id_separator,
|
14
|
-
:annotation_method_name, # Set to nil to disable annotated IDs
|
15
|
-
:annotated_id_separator
|
7
|
+
attr_accessor :salt, :character_group_size, :alphabet, :id_length
|
8
|
+
attr_accessor :slug_value_method_name, :annotation_method_name
|
9
|
+
attr_reader :group_separator, :slugged_id_separator, :annotated_id_separator
|
16
10
|
|
17
11
|
def initialize
|
18
12
|
@character_group_size = 4
|
@@ -24,6 +18,33 @@ module EncodedId
|
|
24
18
|
@annotation_method_name = :annotation_for_encoded_id
|
25
19
|
@annotated_id_separator = "_"
|
26
20
|
end
|
21
|
+
|
22
|
+
# Perform validation vs alphabet on these assignments
|
23
|
+
|
24
|
+
def group_separator=(value)
|
25
|
+
unless valid_separator?(value, alphabet)
|
26
|
+
raise ArgumentError, "Group separator characters must not be part of the alphabet"
|
27
|
+
end
|
28
|
+
@group_separator = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def slugged_id_separator=(value)
|
32
|
+
if value.blank? || value == group_separator || !valid_separator?(value, alphabet)
|
33
|
+
raise ArgumentError, "Slugged ID separator characters must not be part of the alphabet or the same as the group separator"
|
34
|
+
end
|
35
|
+
@slugged_id_separator = value
|
36
|
+
end
|
37
|
+
|
38
|
+
def annotated_id_separator=(value)
|
39
|
+
if value.blank? || value == group_separator || !valid_separator?(value, alphabet)
|
40
|
+
raise ArgumentError, "Annotated ID separator characters must not be part of the alphabet or the same as the group separator"
|
41
|
+
end
|
42
|
+
@annotated_id_separator = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def valid_separator?(separator, characters)
|
46
|
+
separator.chars.none? { |v| characters.include?(v) }
|
47
|
+
end
|
27
48
|
end
|
28
49
|
end
|
29
50
|
end
|
@@ -10,6 +10,7 @@ module EncodedId
|
|
10
10
|
|
11
11
|
def decode_encoded_id(slugged_encoded_id, options = {})
|
12
12
|
return if slugged_encoded_id.blank?
|
13
|
+
raise StandardError, "You must pass a string encoded ID" unless slugged_encoded_id.is_a?(String)
|
13
14
|
annotated_encoded_id = SluggedIdParser.new(slugged_encoded_id, separator: EncodedId::Rails.configuration.slugged_id_separator).id
|
14
15
|
encoded_id = AnnotatedIdParser.new(annotated_encoded_id, separator: EncodedId::Rails.configuration.annotated_id_separator).id
|
15
16
|
return if !encoded_id || encoded_id.blank?
|
@@ -27,9 +28,9 @@ module EncodedId
|
|
27
28
|
EncodedId::Rails::Coder.new(
|
28
29
|
salt: options[:salt] || encoded_id_salt,
|
29
30
|
id_length: options[:id_length] || config.id_length,
|
30
|
-
character_group_size: options[:character_group_size]
|
31
|
+
character_group_size: options.key?(:character_group_size) ? options[:character_group_size] : config.character_group_size,
|
31
32
|
alphabet: options[:alphabet] || config.alphabet,
|
32
|
-
separator: options[:separator]
|
33
|
+
separator: options.key?(:separator) ? options[:separator] : config.group_separator
|
33
34
|
)
|
34
35
|
end
|
35
36
|
end
|
@@ -41,4 +41,30 @@ EncodedId::Rails.configure do |config|
|
|
41
41
|
# Default: 8
|
42
42
|
#
|
43
43
|
# config.id_length = 8
|
44
|
+
|
45
|
+
# The name of the method that returns the value to be used in the slug.
|
46
|
+
#
|
47
|
+
# Default: :name_for_encoded_id_slug
|
48
|
+
#
|
49
|
+
# config.slug_value_method_name = :name_for_encoded_id_slug
|
50
|
+
|
51
|
+
# The separator used between the slug and the encoded ID.
|
52
|
+
# `nil` disables grouping.
|
53
|
+
#
|
54
|
+
# Default: "--"
|
55
|
+
#
|
56
|
+
# config.slugged_id_separator = "--"
|
57
|
+
|
58
|
+
# The name of the method that returns the annotation to be used in the annotated ID.
|
59
|
+
#
|
60
|
+
# Default: :annotation_for_encoded_id
|
61
|
+
#
|
62
|
+
# config.annotation_method_name = :annotation_for_encoded_id
|
63
|
+
|
64
|
+
# The separator used between the annotation and the encoded ID.
|
65
|
+
# `nil` disables annotation.
|
66
|
+
#
|
67
|
+
# Default: "_"
|
68
|
+
#
|
69
|
+
# config.annotated_id_separator = "_"
|
44
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encoded_id-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -56,14 +56,28 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.0.0.
|
59
|
+
version: 1.0.0.rc4
|
60
60
|
type: :runtime
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 1.0.0.
|
66
|
+
version: 1.0.0.rc4
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: appraisal
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
67
81
|
description: ActiveRecord concern to use EncodedID to turn IDs into reversible and
|
68
82
|
human friendly obfuscated strings.
|
69
83
|
email:
|
@@ -73,14 +87,20 @@ extensions: []
|
|
73
87
|
extra_rdoc_files: []
|
74
88
|
files:
|
75
89
|
- ".standard.yml"
|
90
|
+
- Appraisals
|
76
91
|
- CHANGELOG.md
|
77
92
|
- Gemfile
|
78
93
|
- LICENSE.txt
|
79
94
|
- README.md
|
80
95
|
- Rakefile
|
81
96
|
- Steepfile
|
82
|
-
- gemfiles/
|
97
|
+
- gemfiles/.bundle/config
|
98
|
+
- gemfiles/rails_6.1.gemfile
|
99
|
+
- gemfiles/rails_6.1.gemfile.lock
|
83
100
|
- gemfiles/rails_7.0.gemfile
|
101
|
+
- gemfiles/rails_7.0.gemfile.lock
|
102
|
+
- gemfiles/rails_7.1.gemfile
|
103
|
+
- gemfiles/rails_7.1.gemfile.lock
|
84
104
|
- lib/encoded_id/rails.rb
|
85
105
|
- lib/encoded_id/rails/annotated_id.rb
|
86
106
|
- lib/encoded_id/rails/annotated_id_parser.rb
|
@@ -119,11 +139,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
139
|
version: 2.6.0
|
120
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
141
|
requirements:
|
122
|
-
- - "
|
142
|
+
- - ">="
|
123
143
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
144
|
+
version: '0'
|
125
145
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
146
|
+
rubygems_version: 3.5.3
|
127
147
|
signing_key:
|
128
148
|
specification_version: 4
|
129
149
|
summary: Use `encoded_id` with ActiveRecord models
|
data/gemfiles/rails_6.0.gemfile
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gem "sqlite3"
|
4
|
-
gem "activesupport", "~> 6.1.7", ">= 6.1.0"
|
5
|
-
gem "activerecord", "~> 6.1.7", ">= 6.1.0"
|
6
|
-
gem "rake", "~> 13.0"
|
7
|
-
gem "minitest", "~> 5.0"
|
8
|
-
gem "standard", "~> 1.3"
|
9
|
-
gem "steep", "~> 1.2"
|
10
|
-
|
11
|
-
gemspec path: "../"
|