lite-uxid 1.5.0 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -1
- data/lib/generators/lite/uxid/templates/install.rb +1 -0
- data/lib/lite/uxid/base/irreversible.rb +0 -4
- data/lib/lite/uxid/nanoid.rb +27 -2
- data/lib/lite/uxid/record/hashid.rb +3 -1
- data/lib/lite/uxid/record/nanoid.rb +2 -1
- data/lib/lite/uxid/record/ulid.rb +2 -1
- data/lib/lite/uxid/record/uuid.rb +2 -1
- data/lib/lite/uxid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d000996f6e79fc0122e86a88c034391d9853146de2af1e44a1da19234ad538b1
|
4
|
+
data.tar.gz: 932aa03aeb3f62c58cb96328d38d9bc97ca09cc15f5f9a617147464448a45856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1241d664904c1db3b9008bbd70bfb509070dc7adab95313ab5cac6a859fafeb6254f902ab0664086163bfa6d5998643d7f74f059525206d9354214f5595767ac
|
7
|
+
data.tar.gz: 51df74a8df875bbe8e67179960953d6ab54f8f49c11ab5783e90e5c31f6b8e8022ecf1074439083341cbdf9c40dce070c102d29bb947dd148b362f1dabdfc6a6
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.5.2] - 2024-09-20
|
10
|
+
### Changed
|
11
|
+
- Fixed nanoid of differing length error
|
12
|
+
|
13
|
+
## [1.5.1] - 2024-09-20
|
14
|
+
### Changed
|
15
|
+
- Use after commit on create instead of after create
|
16
|
+
|
9
17
|
## [1.5.0] - 2024-09-20
|
10
18
|
### Added
|
11
19
|
- Added uuid version option
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -126,7 +126,15 @@ Passable options are:
|
|
126
126
|
Add the following attribute to all corresponding tables.
|
127
127
|
|
128
128
|
```ruby
|
129
|
-
|
129
|
+
# NOTE: null: true has to be set for HashID's
|
130
|
+
# since an ID must exist before it gets created.
|
131
|
+
t.string :uxid, null: false, index: { unique: true }
|
132
|
+
```
|
133
|
+
|
134
|
+
If using UUID and your database supports it:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
t.uuid :uxid, null: false, index: { unique: true }
|
130
138
|
```
|
131
139
|
|
132
140
|
**Setup**
|
data/lib/lite/uxid/nanoid.rb
CHANGED
@@ -5,13 +5,38 @@ module Lite
|
|
5
5
|
class Nanoid < Base::Irreversible
|
6
6
|
|
7
7
|
def encode
|
8
|
-
uxid =
|
9
|
-
|
8
|
+
uxid = +""
|
9
|
+
|
10
|
+
loop do
|
11
|
+
cached_bytes = bytes
|
12
|
+
|
13
|
+
(0...step).each do |idx|
|
14
|
+
byte = cached_bytes[idx] & mask
|
15
|
+
char = byte && coder_charset[byte]
|
16
|
+
next unless char
|
17
|
+
|
18
|
+
uxid << char
|
19
|
+
return uxid if uxid.size == coder_size
|
20
|
+
end
|
10
21
|
end
|
11
22
|
|
12
23
|
"#{coder_prefix}#{uxid}"
|
13
24
|
end
|
14
25
|
|
26
|
+
private
|
27
|
+
|
28
|
+
def bytes
|
29
|
+
SecureRandom.random_bytes(coder_size).bytes
|
30
|
+
end
|
31
|
+
|
32
|
+
def mask
|
33
|
+
@mask ||= (2 << (Math.log(coder_length - 1) / Math.log(2))) - 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def step
|
37
|
+
@step = (1.6 * mask * coder_size / coder_length).ceil
|
38
|
+
end
|
39
|
+
|
15
40
|
end
|
16
41
|
end
|
17
42
|
end
|
@@ -10,7 +10,9 @@ module Lite
|
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
12
12
|
included do
|
13
|
-
|
13
|
+
after_commit :callback_generate_uxid!,
|
14
|
+
if: proc { respond_to?(:uxid) && !uxid? },
|
15
|
+
on: :create
|
14
16
|
end
|
15
17
|
|
16
18
|
class_methods do
|
@@ -10,7 +10,8 @@ module Lite
|
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
12
12
|
included do
|
13
|
-
before_create :callback_generate_uxid!,
|
13
|
+
before_create :callback_generate_uxid!,
|
14
|
+
if: proc { respond_to?(:uxid) && !uxid? }
|
14
15
|
end
|
15
16
|
|
16
17
|
def uxid_prefix
|
data/lib/lite/uxid/version.rb
CHANGED