ulid 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -1
- data/lib/ulid/generator.rb +12 -1
- data/lib/ulid/version.rb +1 -1
- data/spec/lib/ulid_spec.rb +22 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c072f00beeac3732fbbee2fe32af5f95e14a4eb516e659f70e9e08c0bc525e01
|
4
|
+
data.tar.gz: f8d7ad8d5e714c142c0309a6e814be406c61519cc6e36adcaccae4982d94b96f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e7aaedb437ae82765ec74cf36ddbeb5b529948c9c65c077a0e648156c21ebb23dc26f2e85b3430434dd1babfaaa1b4b1d8bfd00c8dbf9f09f332bad33b93f97
|
7
|
+
data.tar.gz: 01f353360ca4b82534de75f8e715d872b9c976a85655a9f419dfc1a93b6e867d0bea342ad970a3b4653048f3484bba1bc8842f75980142869d13005d3fabc1e7
|
data/.github/FUNDING.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ulid (1.
|
4
|
+
ulid (1.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -24,7 +24,7 @@ GEM
|
|
24
24
|
pry (~> 0.10)
|
25
25
|
rainbow (2.2.2)
|
26
26
|
rake
|
27
|
-
rake (
|
27
|
+
rake (13.0.1)
|
28
28
|
rubocop (0.50.0)
|
29
29
|
parallel (~> 1.10)
|
30
30
|
parser (>= 2.3.3.1, < 3.0)
|
data/README.md
CHANGED
data/lib/ulid/generator.rb
CHANGED
@@ -48,7 +48,18 @@ module ULID
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def time_48bit(time = Time.now)
|
51
|
-
|
51
|
+
# Avoid `time.to_f` since we want to accurately represent a whole number of milliseconds:
|
52
|
+
#
|
53
|
+
# > time = Time.new(2020, 1, 5, 7, 3, Rational(2, 1000))
|
54
|
+
# => 2020-01-05 07:03:00 +0000
|
55
|
+
# > (time.to_f * 1000).to_i
|
56
|
+
# => 1578207780001
|
57
|
+
#
|
58
|
+
# vs
|
59
|
+
#
|
60
|
+
# > (time.to_r * 1000).to_i
|
61
|
+
# => 1578207780002
|
62
|
+
time_ms = (time.to_r * 1000).to_i
|
52
63
|
[time_ms].pack('Q>')[2..-1]
|
53
64
|
end
|
54
65
|
|
data/lib/ulid/version.rb
CHANGED
data/spec/lib/ulid_spec.rb
CHANGED
@@ -25,10 +25,30 @@ describe ULID do
|
|
25
25
|
|
26
26
|
it 'encodes the timestamp in the first 10 characters' do
|
27
27
|
# test case taken from original ulid README:
|
28
|
-
# https://github.com/
|
29
|
-
|
28
|
+
# https://github.com/ulid/javascript#seed-time
|
29
|
+
#
|
30
|
+
# N.b. we avoid specifying the time as a float, since we lose precision:
|
31
|
+
#
|
32
|
+
# > Time.at(1_469_918_176.385).strftime("%F %T.%N")
|
33
|
+
# => "2016-07-30 23:36:16.384999990"
|
34
|
+
#
|
35
|
+
# vs the correct:
|
36
|
+
#
|
37
|
+
# > Time.at(1_469_918_176, 385, :millisecond).strftime("%F %T.%N")
|
38
|
+
# => "2016-07-30 23:36:16.385000000"
|
39
|
+
ulid = ULID.generate(Time.at(1_469_918_176, 385, :millisecond))
|
30
40
|
assert_equal '01ARYZ6S41', ulid[0...10]
|
31
41
|
end
|
42
|
+
|
43
|
+
it 'respects millisecond-precision order' do
|
44
|
+
ulids = Array.new(1000) do |millis|
|
45
|
+
time = Time.new(2020, 1, 2, 3, 4, Rational(millis, 10**3))
|
46
|
+
|
47
|
+
ULID.generate(time)
|
48
|
+
end
|
49
|
+
|
50
|
+
assert_equal(ulids, ulids.sort)
|
51
|
+
end
|
32
52
|
end
|
33
53
|
|
34
54
|
describe 'underlying binary' do
|
metadata
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ulid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Sales
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email:
|
15
15
|
- rafaelcds@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".github/FUNDING.yml"
|
20
21
|
- ".github/workflows/ruby.yml"
|
21
22
|
- ".gitignore"
|
22
23
|
- ".rubocop.yml"
|
@@ -55,9 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
56
|
- !ruby/object:Gem::Version
|
56
57
|
version: '0'
|
57
58
|
requirements: []
|
58
|
-
|
59
|
-
|
60
|
-
signing_key:
|
59
|
+
rubygems_version: 3.1.2
|
60
|
+
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Universally Unique Lexicographically Sortable Identifier implementation for
|
63
63
|
Ruby
|