lite-uxid 1.2.0 → 1.3.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +29 -8
- data/benchmarks/compare.rb +9 -1
- data/lib/lite/uxid/record/uuid.rb +25 -0
- data/lib/lite/uxid/uuid.rb +15 -0
- data/lib/lite/uxid/version.rb +1 -1
- data/lib/lite/uxid.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e12d0fcd0ea1e1653d22eea382fb4d770aa50dda8d9cfebc3a0633e50e01c64d
|
4
|
+
data.tar.gz: 4eb22adb047d392dc1ee1645b9465c98940137f2b562635f8678d08398dc06af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 831968f72b1e450f5caaa4b330f236b2c0b1c6780dfe4153d68265f7a53752e12090b589c7235e92c16fd2e1ce2e58da8df7ef6321b47d13c02d514c4bb9f7f1
|
7
|
+
data.tar.gz: d8491cec5de3a930c968992b2b159691b041549c890ed77a9369b5edaffda1bb6592cba992ad4f7284cd297cc7646c9b5dcefe6f64156fba08e959be57280c68
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -28,6 +28,7 @@ Or install it yourself as:
|
|
28
28
|
* [Hashid](#hashid)
|
29
29
|
* [NanoID](#nanoid)
|
30
30
|
* [ULID](#ulid)
|
31
|
+
* [UUID](#uuid)
|
31
32
|
* [Options](#options)
|
32
33
|
* [ActiveRecord](#active_record)
|
33
34
|
* [Benchmarks](#benchmarks)
|
@@ -49,27 +50,35 @@ end
|
|
49
50
|
|
50
51
|
## Hashid
|
51
52
|
|
52
|
-
|
53
|
+
[More information](https://hashids.org)
|
53
54
|
|
54
55
|
```ruby
|
55
|
-
Lite::Uxid::Hashid.encode(10)
|
56
|
-
Lite::Uxid::Hashid.decode('
|
56
|
+
Lite::Uxid::Hashid.encode(10) #=> '67wGI0'
|
57
|
+
Lite::Uxid::Hashid.decode('67wGI0') #=> 10
|
57
58
|
```
|
58
59
|
|
59
60
|
## NanoID
|
60
61
|
|
61
|
-
|
62
|
+
[More information](https://github.com/ai/nanoid)
|
62
63
|
|
63
64
|
```ruby
|
64
|
-
Lite::Uxid::Nanoid.encode #=> '
|
65
|
+
Lite::Uxid::Nanoid.encode #=> 'sMuNUa3Cegn6r5GRQ4Ij2'
|
65
66
|
```
|
66
67
|
|
67
68
|
## ULID
|
68
69
|
|
69
|
-
|
70
|
+
[More information](https://github.com/ulid/spec)
|
70
71
|
|
71
72
|
```ruby
|
72
|
-
Lite::Uxid::Ulid.encode #=> '
|
73
|
+
Lite::Uxid::Ulid.encode #=> '01gial8st6qrroptaks2tj4smq'
|
74
|
+
```
|
75
|
+
|
76
|
+
## UUID
|
77
|
+
|
78
|
+
[More information](https://en.wikipedia.org/wiki/Universally_unique_identifier)
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Lite::Uxid::Uuid.encode #=> '4376a67e-1189-44b3-a599-7f7566bf105b'
|
73
82
|
```
|
74
83
|
|
75
84
|
## Options
|
@@ -115,6 +124,13 @@ class User < ActiveRecord::Base
|
|
115
124
|
end
|
116
125
|
```
|
117
126
|
|
127
|
+
#### UUID
|
128
|
+
```ruby
|
129
|
+
class User < ActiveRecord::Base
|
130
|
+
include Lite::Uxid::Record::Uuid
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
118
134
|
**Usage**
|
119
135
|
|
120
136
|
Using one of the mixins above provides a handy method to find records by uxid.
|
@@ -134,10 +150,15 @@ User.find_by_uxid!('x123') #=> Raises an ActiveRecord::RecordNotFound error if n
|
|
134
150
|
|
135
151
|
## Benchmarks
|
136
152
|
|
137
|
-
The classes ranked from fastest to slowest are `Hashid`, `Nanoid`, and `Ulid`.
|
153
|
+
The classes ranked from fastest to slowest are `UUID`, `Hashid`, `Nanoid`, and `Ulid`.
|
138
154
|
|
139
155
|
View how each compares by running the [benchmarks](https://github.com/drexed/lite-uxid/tree/master/benchmarks).
|
140
156
|
|
157
|
+
#### Alternatives
|
158
|
+
|
159
|
+
Learn more about alternative functions and more advance hashing setups:
|
160
|
+
[hashids.org](https://hashids.org)
|
161
|
+
|
141
162
|
## Development
|
142
163
|
|
143
164
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/benchmarks/compare.rb
CHANGED
@@ -7,16 +7,24 @@ require "lite/uxid"
|
|
7
7
|
|
8
8
|
Benchmark.ips do |x|
|
9
9
|
x.report("Hashid") do
|
10
|
-
|
10
|
+
id = rand(1..1_000_000)
|
11
|
+
Lite::Uxid::Hashid.encode(id)
|
11
12
|
end
|
12
13
|
|
13
14
|
x.report("NanoID") do
|
15
|
+
_id = rand(1..1_000_000) # To simulate the extra work from `rand`
|
14
16
|
Lite::Uxid::Nanoid.encode
|
15
17
|
end
|
16
18
|
|
17
19
|
x.report("ULID") do
|
20
|
+
_id = rand(1..1_000_000) # To simulate the extra work from `rand`
|
18
21
|
Lite::Uxid::Ulid.encode
|
19
22
|
end
|
20
23
|
|
24
|
+
x.report("UUID") do
|
25
|
+
_id = rand(1..1_000_000) # To simulate the extra work from `rand`
|
26
|
+
Lite::Uxid::Uuid.encode
|
27
|
+
end
|
28
|
+
|
21
29
|
x.compare!
|
22
30
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support" unless defined?(ActiveSupport)
|
4
|
+
|
5
|
+
module Lite
|
6
|
+
module Uxid
|
7
|
+
module Record
|
8
|
+
module Uuid
|
9
|
+
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
included do
|
13
|
+
before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) && !uxid? }
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def callback_generate_uxid!
|
19
|
+
self.uxid = Lite::Uxid::Uuid.encode
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/lite/uxid/version.rb
CHANGED
data/lib/lite/uxid.rb
CHANGED
@@ -9,6 +9,8 @@ require "lite/uxid/reversible"
|
|
9
9
|
require "lite/uxid/record/hashid"
|
10
10
|
require "lite/uxid/record/nanoid"
|
11
11
|
require "lite/uxid/record/ulid"
|
12
|
+
require "lite/uxid/record/uuid"
|
12
13
|
require "lite/uxid/hashid"
|
13
14
|
require "lite/uxid/nanoid"
|
14
15
|
require "lite/uxid/ulid"
|
16
|
+
require "lite/uxid/uuid"
|
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.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -224,8 +224,10 @@ files:
|
|
224
224
|
- lib/lite/uxid/record/hashid.rb
|
225
225
|
- lib/lite/uxid/record/nanoid.rb
|
226
226
|
- lib/lite/uxid/record/ulid.rb
|
227
|
+
- lib/lite/uxid/record/uuid.rb
|
227
228
|
- lib/lite/uxid/reversible.rb
|
228
229
|
- lib/lite/uxid/ulid.rb
|
230
|
+
- lib/lite/uxid/uuid.rb
|
229
231
|
- lib/lite/uxid/version.rb
|
230
232
|
- lite-uxid.gemspec
|
231
233
|
homepage: http://drexed.github.io/lite-uxid
|