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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8119c92432950cdd4fd849aafd041832a8f4ceee022c7f38009681726bb1181a
4
- data.tar.gz: 121d26ff5203b65b8a4b148f9f82aad5585c4baeae6ae1008e71cc057d6fc1f8
3
+ metadata.gz: e12d0fcd0ea1e1653d22eea382fb4d770aa50dda8d9cfebc3a0633e50e01c64d
4
+ data.tar.gz: 4eb22adb047d392dc1ee1645b9465c98940137f2b562635f8678d08398dc06af
5
5
  SHA512:
6
- metadata.gz: 4ed1ddf45549eef5ee6b6950b000272b8d62dfa8ac5b403fa5e6ffc70dfabd9a03978a7e96259184b3222b42e3b1dc240e44984ee89086cfe3f396e7fcfa3d8c
7
- data.tar.gz: c63df74d2affbda2f3fefc86a0b5d44364dfef7417b22c6c56f7d411808d3935d1b26f06de92d8699f3ababaf8c84a9e3a0149123a3ed66d52e92bf59f064192
6
+ metadata.gz: 831968f72b1e450f5caaa4b330f236b2c0b1c6780dfe4153d68265f7a53752e12090b589c7235e92c16fd2e1ce2e58da8df7ef6321b47d13c02d514c4bb9f7f1
7
+ data.tar.gz: d8491cec5de3a930c968992b2b159691b041549c890ed77a9369b5edaffda1bb6592cba992ad4f7284cd297cc7646c9b5dcefe6f64156fba08e959be57280c68
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.0] - 2022-11-20
10
+ ### Added
11
+ - Added uuid option
12
+
9
13
  ## [1.2.0] - 2022-11-19
10
14
  ### Added
11
15
  - Added individual character and length options
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-uxid (1.2.0)
4
+ lite-uxid (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- Hashid's are reversible and is the most performant generator.
53
+ [More information](https://hashids.org)
53
54
 
54
55
  ```ruby
55
- Lite::Uxid::Hashid.encode(10) #=> 'q5D8inm0'
56
- Lite::Uxid::Hashid.decode('q5D8inm0') #=> 10
56
+ Lite::Uxid::Hashid.encode(10) #=> '67wGI0'
57
+ Lite::Uxid::Hashid.decode('67wGI0') #=> 10
57
58
  ```
58
59
 
59
60
  ## NanoID
60
61
 
61
- NanoID are irreversible and are the second fastest ID generator but while unlikely can produce collisions.
62
+ [More information](https://github.com/ai/nanoid)
62
63
 
63
64
  ```ruby
64
- Lite::Uxid::Nanoid.encode #=> '0bmHjB5Gx8FTBqJekX6dS6XIXf'
65
+ Lite::Uxid::Nanoid.encode #=> 'sMuNUa3Cegn6r5GRQ4Ij2'
65
66
  ```
66
67
 
67
68
  ## ULID
68
69
 
69
- ULID are irreversible but provide information outside of just randomness.
70
+ [More information](https://github.com/ulid/spec)
70
71
 
71
72
  ```ruby
72
- Lite::Uxid::Ulid.encode #=> '1mqfg9qa96s8s5f02o1ucf8lcc'
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.
@@ -7,16 +7,24 @@ require "lite/uxid"
7
7
 
8
8
  Benchmark.ips do |x|
9
9
  x.report("Hashid") do
10
- Lite::Uxid::Hashid.encode(rand(1..1_000_000))
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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom" unless defined?(SecureRandom)
4
+
5
+ module Lite
6
+ module Uxid
7
+ class Uuid < Irreversible
8
+
9
+ def encode
10
+ SecureRandom.uuid
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Uxid
5
5
 
6
- VERSION = "1.2.0"
6
+ VERSION = "1.3.0"
7
7
 
8
8
  end
9
9
  end
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.2.0
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-19 00:00:00.000000000 Z
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