uuidx 0.9.0 → 0.10.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 +3 -0
- data/README.md +26 -25
- data/lib/{uuid → uuidx}/errors.rb +2 -2
- data/lib/{uuid → uuidx}/gem_version.rb +2 -2
- data/lib/{uuid → uuidx}/version4.rb +3 -3
- data/lib/{uuid → uuidx}/version6.rb +5 -5
- data/lib/{uuid → uuidx}/version7.rb +5 -5
- data/lib/{uuid → uuidx}/version8.rb +3 -3
- data/lib/{uuid.rb → uuidx.rb} +14 -14
- data/sig/{uuid → uuidx}/errors.rbs +1 -1
- data/sig/{uuid → uuidx}/version4.rbs +1 -1
- data/sig/{uuid → uuidx}/version6.rbs +1 -1
- data/sig/{uuid → uuidx}/version7.rbs +1 -1
- data/sig/{uuid → uuidx}/version8.rbs +1 -1
- data/sig/{uuid.rbs → uuidx.rbs} +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ca7c3e75acfde9ce0b2cd6f05d8bdd1c9809e095a7b69200a1a0271c7dcadbe
|
4
|
+
data.tar.gz: d393cb6874eae6ff28a4537a5f634764d3946611e61e00bd5f840ead16179d04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de256df49b04450bc9cc47c3f44ca58af19a77385c7b7b52ad3d856e454e0ff48a2a7325eab9d38a083fcd12091a6663fa57f07ff3f7065bedab5be87756ea26
|
7
|
+
data.tar.gz: 2d8878d99f1086f9867f03d76382e87d30e7c915a1779a73c8dfad47e8e8c9e03cb007307d07b9748fc488659f27b2de2fb0bb6f345ce9f0ee2005f018442b24
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
<h1 align="center">uuidx</h1>
|
2
2
|
<p align="center">Fast Ruby implementations of UUID versions 4, 6, 7, and 8 🪪</p>
|
3
|
+
<p align="center"><a href="https://badge.fury.io/rb/uuidx"><img src="https://badge.fury.io/rb/uuidx.svg" alt="Gem Version" height="18"></a></p>
|
3
4
|
|
4
5
|
---
|
5
6
|
|
@@ -38,9 +39,9 @@ the library and call the associated method.
|
|
38
39
|
```ruby
|
39
40
|
require "uuidx"
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
Uuidx.v4 # => "2b54639d-e43e-489f-9c64-30ecdcac3c95"
|
43
|
+
Uuidx.v6 # => "1eda9761-9f6f-6414-8c5f-fd61f1239907"
|
44
|
+
Uuidx.v7 # => "01863d24-6d1e-78ba-92ee-6e80c79c4e28"
|
44
45
|
```
|
45
46
|
|
46
47
|
These methods all use default generators and are thread-safe. However, if you
|
@@ -50,9 +51,9 @@ the generators you are using when each child process starts.
|
|
50
51
|
```ruby
|
51
52
|
# Puma example that resets all default generators.
|
52
53
|
on_worker_boot do
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
Uuidx.reset_v4!
|
55
|
+
Uuidx.reset_v6!
|
56
|
+
Uuidx.reset_v7!
|
56
57
|
end
|
57
58
|
```
|
58
59
|
|
@@ -60,13 +61,13 @@ This way you will get thread-safe state access per process without requiring
|
|
60
61
|
IPC.
|
61
62
|
|
62
63
|
### Monotonicity & Batching
|
63
|
-
The simple API provided by `
|
64
|
+
The simple API provided by `Uuidx` also supports monotonic batches. Provide the
|
64
65
|
batch size and you will receive an array of UUID values back.
|
65
66
|
|
66
67
|
```ruby
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
Uuidx.batch_v4(10) # => ["2b54639d-e43e-489f-9c64-30ecdcac3c95", ...]
|
69
|
+
Uuidx.batch_v6(10) # => ["1eda9761-9f6f-6414-8c5f-fd61f1239907", ...]
|
70
|
+
Uuidx.batch_v7(10) # => ["01863d24-6d1e-78ba-92ee-6e80c79c4e28", ...]
|
70
71
|
```
|
71
72
|
|
72
73
|
### Advanced Usage
|
@@ -74,7 +75,7 @@ If you require multiple generators you can drop below the simple API presented
|
|
74
75
|
above to create generators directly.
|
75
76
|
|
76
77
|
```ruby
|
77
|
-
v6 =
|
78
|
+
v6 = Uuidx::Version6.new
|
78
79
|
v6.generate # => "1eda9adc-2ed9-629e-9a02-4d2ccc87c569"
|
79
80
|
```
|
80
81
|
|
@@ -91,21 +92,21 @@ a generator directly. It takes a single parameter to its constructor which must
|
|
91
92
|
be the class name of your UUID v8 definition.
|
92
93
|
|
93
94
|
```ruby
|
94
|
-
v8 =
|
95
|
+
v8 = Uuidx::Version8.new(MyV8Definition)
|
95
96
|
v8.generate # => "..."
|
96
97
|
```
|
97
98
|
|
98
99
|
The definition class should implement the methods `custom_a`, `custom_b`, and
|
99
100
|
`custom_c` in order to fill out the UUID data [according to the draft](https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-uuid-version-8).
|
100
101
|
|
101
|
-
See the [documentation for Version8](https://tinychameleon.github.io/uuidx/
|
102
|
+
See the [documentation for Version8](https://tinychameleon.github.io/uuidx/Uuidx/Version8.html) for precise details.
|
102
103
|
|
103
104
|
#### Batching
|
104
|
-
Any custom UUID v8 generators can also participate in
|
105
|
-
|
105
|
+
Any custom UUID v8 generators can also participate in batching by using the
|
106
|
+
`batch` method. The thread-safety of this depends on your UUID v8 implementation.
|
106
107
|
|
107
108
|
```ruby
|
108
|
-
|
109
|
+
Uuidx.batch(v8, 10) # => ["<a v8 uuidx>", ...]
|
109
110
|
```
|
110
111
|
|
111
112
|
### Clock Resolution
|
@@ -115,24 +116,24 @@ is raised if the system has insufficient precision.
|
|
115
116
|
|
116
117
|
```ruby
|
117
118
|
begin
|
118
|
-
|
119
|
-
rescue
|
119
|
+
Uuidx::Version6.verify_clock_resolution! # or Uuidx::Version7
|
120
|
+
rescue Uuidx::ClockResolutionError
|
120
121
|
# ...
|
121
122
|
end
|
122
123
|
```
|
123
124
|
|
124
125
|
The API documentation has details about what the clock resolution must be for
|
125
126
|
each of the UUID versions. See the
|
126
|
-
[Version 6](https://tinychameleon.github.io/uuidx/
|
127
|
-
[Version 7](https://tinychameleon.github.io/uuidx/
|
127
|
+
[Version 6](https://tinychameleon.github.io/uuidx/Uuidx/Version6.html) and
|
128
|
+
[Version 7](https://tinychameleon.github.io/uuidx/Uuidx/Version7.html)
|
128
129
|
documentation for details.
|
129
130
|
|
130
131
|
### A Note on Clock Timings
|
131
132
|
The API documentation contains specific details around how the implementations
|
132
133
|
deal with clock drift. See the
|
133
|
-
[
|
134
|
-
[Version 6](https://tinychameleon.github.io/uuidx/
|
135
|
-
[Version 7](https://tinychameleon.github.io/uuidx/
|
134
|
+
[Uuidx](https://tinychameleon.github.io/uuidx/Uuidx.html),
|
135
|
+
[Version 6](https://tinychameleon.github.io/uuidx/Uuidx/Version6.html), and
|
136
|
+
[Version 7](https://tinychameleon.github.io/uuidx/Uuidx/Version7.html)
|
136
137
|
documentation for more information.
|
137
138
|
|
138
139
|
## Performance
|
@@ -183,9 +184,9 @@ To release a new version:
|
|
183
184
|
|
184
185
|
1. ensure the documentation and changelog are ready
|
185
186
|
2. run `bundle exec rake rdoc` to generate the new documentation and commit it
|
186
|
-
3. update the version number in `lib/
|
187
|
+
3. update the version number in `lib/uuidx/gem_version.rb`
|
187
188
|
4. run `bundle install` to update the `Gemfile.lock`
|
188
|
-
5. create a release commit with
|
189
|
+
5. create a release commit with these updates
|
189
190
|
6. run `bundle exec rake release` to tag and push the version to RubyGems
|
190
191
|
|
191
192
|
## Contributing
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require "securerandom"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Uuidx
|
6
6
|
# UUID Version 7 defined by the
|
7
7
|
# {RFC 4122 BIS-01 Draft}[https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-uuid-version-4].
|
8
8
|
#
|
9
9
|
# To construct a new UUID v4 value create a generator, then use #generate.
|
10
|
-
# g =
|
10
|
+
# g = Uuidx::Version4.new
|
11
11
|
# g.generate # => "2b54639d-e43e-489f-9c64-30ecdcac3c95"
|
12
12
|
#
|
13
13
|
# The implementation will cache 1024 bytes of random data from +SecureRandom+ to facilitate faster construction.
|
@@ -30,7 +30,7 @@ module Uuid
|
|
30
30
|
@pool = SecureRandom.bytes(NEEDED_BYTES).unpack(UNPACK_FORMAT) if @pool.empty?
|
31
31
|
ab, c = @pool.pop(2)
|
32
32
|
|
33
|
-
|
33
|
+
Uuidx.format(VERSION_VARIANT | ((ab & RANDOM_AB_MASK) << AB_SHIFT) | (c & RANDOM_C_MASK))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require "securerandom"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Uuidx
|
6
6
|
# UUID Version 6 defined by the
|
7
7
|
# {RFC 4122 BIS-01 Draft}[https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-uuid-version-6].
|
8
8
|
#
|
9
9
|
# To construct a new UUID v6 value create a generator, then use #generate.
|
10
|
-
# g =
|
10
|
+
# g = Uuidx::Version6.new
|
11
11
|
# g.generate # => "1eda9761-9f6f-6414-8c5f-fd61f1239907"
|
12
12
|
#
|
13
13
|
# The implementation will use +SecureRandom+ to populate the Node and Clock Sequence bits with a random value
|
@@ -20,8 +20,8 @@ module Uuid
|
|
20
20
|
# you can call ::verify_clock_resolution! and handle the ClockResolutionError as you see fit.
|
21
21
|
#
|
22
22
|
# begin
|
23
|
-
#
|
24
|
-
# rescue
|
23
|
+
# Uuidx::Version6.verify_clock_resolution!
|
24
|
+
# rescue Uuidx::ClockResolutionError
|
25
25
|
# # ...
|
26
26
|
# end
|
27
27
|
#
|
@@ -56,7 +56,7 @@ module Uuid
|
|
56
56
|
ts = GREGORIAN_MICROSECOND_TENTHS + (Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond) / TS_NS_FACTOR)
|
57
57
|
ts = ((ts << TS_MASK_SHIFT) & TS_HIGH_MID_MASK) | (ts & TS_LOW_MASK)
|
58
58
|
|
59
|
-
|
59
|
+
Uuidx.format(VERSION_VARIANT | (ts << TS_POSITIONAL_SHIFT) | @clock_sequence | @node_id)
|
60
60
|
end
|
61
61
|
|
62
62
|
# Reset the generator with a new random node ID and clock sequence.
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
require "securerandom"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Uuidx
|
6
6
|
# UUID Version 7 defined by the
|
7
7
|
# {RFC 4122 BIS-01 Draft}[https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-uuid-version-7].
|
8
8
|
#
|
9
9
|
# To construct a new UUID v7 value create a generator, then use #generate.
|
10
|
-
# g =
|
10
|
+
# g = Uuidx::Version7.new
|
11
11
|
# g.generate # => "01863d24-6d1e-78ba-92ee-6e80c79c4e28"
|
12
12
|
#
|
13
13
|
# The implementation will cache 640 bytes of random data from +SecureRandom+ to facilitate faster construction.
|
@@ -16,8 +16,8 @@ module Uuid
|
|
16
16
|
# you can call ::verify_clock_resolution! and handle the ClockResolutionError as you see fit.
|
17
17
|
#
|
18
18
|
# begin
|
19
|
-
#
|
20
|
-
# rescue
|
19
|
+
# Uuidx::Version7.verify_clock_resolution!
|
20
|
+
# rescue Uuidx::ClockResolutionError
|
21
21
|
# # ...
|
22
22
|
# end
|
23
23
|
#
|
@@ -53,7 +53,7 @@ module Uuid
|
|
53
53
|
ts = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond) & TS_MASK
|
54
54
|
high = (ts << TS_SHIFT) | (a & RAND_A_MASK)
|
55
55
|
|
56
|
-
|
56
|
+
Uuidx.format(VERSION_VARIANT | (high << HIGH_SHIFT) | (b & RAND_B_MASK))
|
57
57
|
end
|
58
58
|
|
59
59
|
# Verify that the clock resolution is capable of 1ms resolution.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module Uuidx
|
4
4
|
# UUID Version 8 defined by the
|
5
5
|
# {RFC 4122 BIS-01 Draft}[https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-uuid-version-8].
|
6
6
|
#
|
@@ -26,7 +26,7 @@ module Uuid
|
|
26
26
|
# - +custom_c+ should generate a 62-bit value which acts as the remaining least significant octets.
|
27
27
|
#
|
28
28
|
# Then create a UUID v8 generator by passing in the class, and call #generate.
|
29
|
-
# g =
|
29
|
+
# g = Uuidx::Version8.new(MyGeneratorDefinition)
|
30
30
|
# g.generate # => "00000000-0001-8002-8000-000000000003"
|
31
31
|
#
|
32
32
|
# The implementation will truncate the results of each generator module method so that they abide by the bit lengths
|
@@ -53,7 +53,7 @@ module Uuid
|
|
53
53
|
high = (a << A_SHIFT) | b
|
54
54
|
c = @definition.custom_c & CUSTOM_C_MASK
|
55
55
|
|
56
|
-
|
56
|
+
Uuidx.format(VERSION_VARIANT | (high << HIGH_SHIFT) | c)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/{uuid.rb → uuidx.rb}
RENAMED
@@ -1,22 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "set"
|
4
|
-
require_relative "
|
5
|
-
require_relative "
|
6
|
-
require_relative "
|
7
|
-
require_relative "
|
8
|
-
require_relative "
|
9
|
-
require_relative "
|
4
|
+
require_relative "uuidx/gem_version"
|
5
|
+
require_relative "uuidx/errors"
|
6
|
+
require_relative "uuidx/version4"
|
7
|
+
require_relative "uuidx/version6"
|
8
|
+
require_relative "uuidx/version7"
|
9
|
+
require_relative "uuidx/version8"
|
10
10
|
|
11
|
-
# The
|
11
|
+
# The Uuidx module contains a simple API to generate v4, v6, and v7 UUIDs
|
12
12
|
# without needing to create generators manually.
|
13
13
|
#
|
14
14
|
# The simple API is exposed as a set of methods ::v4, ::v6, and ::v7 which
|
15
15
|
# handle thread-safety and generator creation.
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
17
|
+
# Uuidx.v4 # => "2b54639d-e43e-489f-9c64-30ecdcac3c95"
|
18
|
+
# Uuidx.v6 # => "1eda9761-9f6f-6414-8c5f-fd61f1239907"
|
19
|
+
# Uuidx.v7 # => "01863d24-6d1e-78ba-92ee-6e80c79c4e28"
|
20
20
|
#
|
21
21
|
# See the Version4, Version6, and Version7 classes for details on how to create
|
22
22
|
# generators manually.
|
@@ -25,9 +25,9 @@ require_relative "uuid/version8"
|
|
25
25
|
# The simple API also provides thread-safe monotonic batch methods which expect
|
26
26
|
# an amount.
|
27
27
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
28
|
+
# Uuidx.batch_v4(10) # => ["2b54639d-e43e-489f-9c64-30ecdcac3c95", ...]
|
29
|
+
# Uuidx.batch_v6(10) # => ["1eda9761-9f6f-6414-8c5f-fd61f1239907", ...]
|
30
|
+
# Uuidx.batch_v7(10) # => ["01863d24-6d1e-78ba-92ee-6e80c79c4e28", ...]
|
31
31
|
#
|
32
32
|
# Monotonicity has little meaning with UUID v4, but the batches are ordered for
|
33
33
|
# consistency.
|
@@ -39,7 +39,7 @@ require_relative "uuid/version8"
|
|
39
39
|
# within the timestamp values.
|
40
40
|
#
|
41
41
|
# See the Version6 and Version7 documentation for manifestation details.
|
42
|
-
module
|
42
|
+
module Uuidx
|
43
43
|
# The nil UUID as defined by
|
44
44
|
# {§5.10 of RFC 4122 BIS-01}[https://www.ietf.org/archive/id/draft-ietf-uuidrev-rfc4122bis-01.html#name-nil-uuid].
|
45
45
|
#
|
data/sig/{uuid.rbs → uuidx.rbs}
RENAMED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uuidx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephan Tarulli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "A fast Ruby implementation of UUID versions 4, 6, 7, and 8 \U0001FAAA"
|
14
14
|
email:
|
@@ -20,19 +20,19 @@ files:
|
|
20
20
|
- CHANGELOG.md
|
21
21
|
- LICENSE.txt
|
22
22
|
- README.md
|
23
|
-
- lib/
|
24
|
-
- lib/
|
25
|
-
- lib/
|
26
|
-
- lib/
|
27
|
-
- lib/
|
28
|
-
- lib/
|
29
|
-
- lib/
|
30
|
-
- sig/
|
31
|
-
- sig/
|
32
|
-
- sig/
|
33
|
-
- sig/
|
34
|
-
- sig/
|
35
|
-
- sig/
|
23
|
+
- lib/uuidx.rb
|
24
|
+
- lib/uuidx/errors.rb
|
25
|
+
- lib/uuidx/gem_version.rb
|
26
|
+
- lib/uuidx/version4.rb
|
27
|
+
- lib/uuidx/version6.rb
|
28
|
+
- lib/uuidx/version7.rb
|
29
|
+
- lib/uuidx/version8.rb
|
30
|
+
- sig/uuidx.rbs
|
31
|
+
- sig/uuidx/errors.rbs
|
32
|
+
- sig/uuidx/version4.rbs
|
33
|
+
- sig/uuidx/version6.rbs
|
34
|
+
- sig/uuidx/version7.rbs
|
35
|
+
- sig/uuidx/version8.rbs
|
36
36
|
homepage: https://github.com/tinychameleon/uuidx
|
37
37
|
licenses:
|
38
38
|
- MIT
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
rubygems_version: 3.4.
|
61
|
+
rubygems_version: 3.4.7
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: "A fast Ruby implementation of UUID versions 4, 6, 7, and 8 \U0001FAAA"
|