ruby-ulid 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 358b03a503f8a12c87f3f7daaf3b0acf6e55dc44f1aba7a38b9f9a38985c2c68
4
- data.tar.gz: 15d25d443f4826b07fc9a74b092e35b9cd60dc34cc3615f03fee619d4fc39445
3
+ metadata.gz: 7b50cb3fee0b304a62ebd460e7d08b932d3c58c1f7810a1dc24b5166df10ceaf
4
+ data.tar.gz: b84a2ad766640fa7c87e4bbb5b0fdd637bf831407f235989cdd043ea5b1189aa
5
5
  SHA512:
6
- metadata.gz: 5b18d13597bd2f3dcd85a15a26d9086fb9a80b91775292c9da82d93144b6abd37585996f1bf64dfc4ac12b6d6d49683012dfea8e04624005358459667864114c
7
- data.tar.gz: d987aa9b60717577fae96eef68fca76b2395f11a580df4863a69dd0931d955e4cf68608c101959db18f5e3a26031fbe284ff90a0d107fa84bbebb63949bba66b
6
+ metadata.gz: e44eadac5ad4c83f1c8da74fbfa502a3b3b7293dda8eb44855bb477070687afd815d46237a9cc15266223f7cd0981b69670165767b366156d23728cdb76c878e
7
+ data.tar.gz: 349b2e8c2b16d5c9ae58270fdb5e87a3c364eef4b3ae2972680cb5de119ba737ed035db36bb7283fc96ff7c7a54663be5de8c0725e0de1975d8f66de34dd052c
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [ulid/spec](https://github.com/ulid/spec) is useful.
9
9
  Especially possess all `uniqueness`, `randomness`, `extractable timestamps` and `sortable` features.
10
10
  This gem aims to provide the generator, monotonic generator, parser and handy manipulation features around ULID.
11
- Also providing [ruby/rbs](https://github.com/ruby/rbs) signatures.
11
+ Also providing [RBS](https://github.com/ruby/rbs) signatures.
12
12
 
13
13
  ---
14
14
 
@@ -47,21 +47,43 @@ $ gem install ruby-ulid
47
47
  Should be installed!
48
48
  ```
49
49
 
50
- Add this line to your Gemfile`.
50
+ Add this line in your Gemfile.
51
51
 
52
52
  ```ruby
53
- gem('ruby-ulid', '~> 0.2.2')
53
+ gem('ruby-ulid', '~> 0.4.0')
54
54
  ```
55
55
 
56
- ### Generator and Parser
57
-
58
- The generated `ULID` is an object not just a string.
59
- It means easily get the timestamps and binary formats.
56
+ ### How to use
60
57
 
61
58
  ```ruby
62
59
  require 'ulid'
63
60
 
61
+ defined? ULID
62
+ # => "constant"
63
+ ```
64
+
65
+ ### Basic Generator
66
+
67
+ The generated `ULID` is an object not just a string.
68
+
69
+ ```ruby
64
70
  ulid = ULID.generate #=> ULID(2021-04-27 17:27:22.826 UTC: 01F4A5Y1YAQCYAYCTC7GRMJ9AA)
71
+ ```
72
+
73
+ ### Parser
74
+
75
+ You can get the objects from exists encoded ULIDs.
76
+
77
+ ```ruby
78
+ ulid = ULID.parse('01ARZ3NDEKTSV4RRFFQ69G5FAV') #=> ULID(2016-07-30 23:54:10.259 UTC: 01ARZ3NDEKTSV4RRFFQ69G5FAV)
79
+ ```
80
+
81
+ ### ULID object
82
+
83
+ You can extract timestamps and binary formats.
84
+
85
+ ```ruby
86
+ ulid = ULID.parse('01F4A5Y1YAQCYAYCTC7GRMJ9AA') #=> ULID(2021-04-27 17:27:22.826 UTC: 01F4A5Y1YAQCYAYCTC7GRMJ9AA)
65
87
  ulid.to_time #=> 2021-04-27 17:27:22.826 UTC
66
88
  ulid.milliseconds #=> 1619544442826
67
89
  ulid.to_s #=> "01F4A5Y1YAQCYAYCTC7GRMJ9AA"
@@ -71,16 +93,9 @@ ulid.to_i #=> 1957909092946624190749577070267409738
71
93
  ulid.octets #=> [1, 121, 20, 95, 7, 202, 187, 60, 175, 51, 76, 60, 49, 73, 37, 74]
72
94
  ```
73
95
 
74
- You can get the objects from exists encoded ULIDs
75
-
76
- ```ruby
77
- ulid = ULID.parse('01ARZ3NDEKTSV4RRFFQ69G5FAV') #=> ULID(2016-07-30 23:54:10.259 UTC: 01ARZ3NDEKTSV4RRFFQ69G5FAV)
78
- ulid.to_time #=> 2016-07-30 23:54:10.259 UTC
79
- ```
80
-
81
96
  ### Sortable with the timestamp
82
97
 
83
- ULIDs are sortable when they are generated in different timestamp with milliseconds precision
98
+ ULIDs are sortable when they are generated in different timestamp with milliseconds precision.
84
99
 
85
100
  ```ruby
86
101
  ulids = 1000.times.map do
@@ -91,7 +106,7 @@ ulids.uniq(&:to_time).size #=> 1000
91
106
  ulids.sort == ulids #=> true
92
107
  ```
93
108
 
94
- `ULID.generate` can take fixed `Time` instance. The shorthand is `ULID.at`
109
+ `ULID.generate` can take fixed `Time` instance. The shorthand is `ULID.at`.
95
110
 
96
111
  ```ruby
97
112
  time = Time.at(946684800).utc #=> 2000-01-01 00:00:00 UTC
@@ -147,11 +162,11 @@ sample_ulids_by_the_time.take(5) #=>
147
162
  ulids.sort == ulids #=> true
148
163
  ```
149
164
 
150
- Same generator does not generate duplicated ULIDs even in multi threads environment. It is implemented with [Monitor](https://bugs.ruby-lang.org/issues/16255)
165
+ Same generator does not generate duplicated ULIDs even in multi threads environment. It is implemented with [Monitor](https://bugs.ruby-lang.org/issues/16255).
151
166
 
152
167
  ### Filtering IDs with `Time`
153
168
 
154
- `ULID` can be element of the `Range`. If you generated the IDs in monotonic generator, ID based filtering is easy and reliable
169
+ `ULID` can be element of the `Range`. If they were generated with monotonic generator, ID based filtering is easy and reliable.
155
170
 
156
171
  ```ruby
157
172
  include_end = ulid1..ulid2
@@ -187,7 +202,9 @@ time = Time.at(946684800, Rational('123456.789')).utc #=> 2000-01-01 00:00:00.12
187
202
  ULID.floor(time) #=> 2000-01-01 00:00:00.123 UTC
188
203
  ```
189
204
 
190
- ### Scanner for string (e.g. `JSON`)
205
+ ### Some methods to help manipulations
206
+
207
+ #### Scanner for string (e.g. `JSON`)
191
208
 
192
209
  For rough operations, `ULID.scan` might be useful.
193
210
 
@@ -230,7 +247,7 @@ ULID.scan(json).to_a
230
247
  ```
231
248
 
232
249
  `ULID#patterns` is a util for text based operations.
233
- The results and spec are not fixed. Should not be used except snippets/console operation
250
+ The results and spec are not fixed. Should not be used except snippets/console operation.
234
251
 
235
252
  ```ruby
236
253
  ULID.parse('01F4GNBXW1AM2KWW52PVT3ZY9X').patterns
@@ -241,7 +258,7 @@ ULID.parse('01F4GNBXW1AM2KWW52PVT3ZY9X').patterns
241
258
  }
242
259
  ```
243
260
 
244
- ### Some methods to help manipulations
261
+ #### Get boundary ULIDs
245
262
 
246
263
  `ULID.min` and `ULID.max` return termination values for ULID spec.
247
264
 
@@ -256,10 +273,12 @@ ULID.min(time) #=> ULID(2000-01-01 00:00:00.123 UTC: 00VHNCZB3V0000000000000000)
256
273
  ULID.max(time) #=> ULID(2000-01-01 00:00:00.123 UTC: 00VHNCZB3VZZZZZZZZZZZZZZZZ)
257
274
  ```
258
275
 
276
+ #### As element in Enumerable
277
+
259
278
  `ULID#next` and `ULID#succ` returns next(successor) ULID.
260
279
  Especially `ULID#succ` makes it possible `Range[ULID]#each`.
261
280
 
262
- NOTE: But basically `Range[ULID]#each` should not be used, incrementing 128 bits IDs are not reasonable operation in most case
281
+ NOTE: However basically `Range[ULID]#each` should not be used. Iincrementing 128 bits IDs are not reasonable operation in most cases.
263
282
 
264
283
  ```ruby
265
284
  ULID.parse('01BX5ZZKBKZZZZZZZZZZZZZZZY').next.to_s #=> "01BX5ZZKBKZZZZZZZZZZZZZZZZ"
@@ -267,7 +286,7 @@ ULID.parse('01BX5ZZKBKZZZZZZZZZZZZZZZZ').next.to_s #=> "01BX5ZZKBM00000000000000
267
286
  ULID.parse('7ZZZZZZZZZZZZZZZZZZZZZZZZZ').next #=> nil
268
287
  ```
269
288
 
270
- `ULID#pred` returns predecessor ULID
289
+ `ULID#pred` returns predecessor ULID.
271
290
 
272
291
  ```ruby
273
292
  ULID.parse('01BX5ZZKBK0000000000000001').pred.to_s #=> "01BX5ZZKBK0000000000000000"
@@ -275,6 +294,8 @@ ULID.parse('01BX5ZZKBK0000000000000000').pred.to_s #=> "01BX5ZZKBJZZZZZZZZZZZZZZ
275
294
  ULID.parse('00000000000000000000000000').pred #=> nil
276
295
  ```
277
296
 
297
+ #### Test helpers
298
+
278
299
  `ULID.sample` returns random ULIDs.
279
300
 
280
301
  Basically ignores generating time.
@@ -300,33 +321,23 @@ ulid1 = ULID.parse('01F4A5Y1YAQCYAYCTC7GRMJ9AA') #=> ULID(2021-04-27 17:27:22.82
300
321
  ulid2 = ULID.parse('01F4PTVCSN9ZPFKYTY2DDJVRK4') #=> ULID(2021-05-02 15:23:48.917 UTC: 01F4PTVCSN9ZPFKYTY2DDJVRK4)
301
322
  ulids = ULID.sample(1000, period: ulid1..ulid2)
302
323
  ulids.uniq.size #=> 1000
303
- ulids.take(10)
324
+ ulids.take(5)
304
325
  #=>
305
326
  #[ULID(2021-05-02 06:57:19.954 UTC: 01F4NXW02JNB8H0J0TK48JD39X),
306
327
  # ULID(2021-05-02 07:06:07.458 UTC: 01F4NYC372GVP7NS0YAYQGT4VZ),
307
328
  # ULID(2021-05-01 06:16:35.791 UTC: 01F4K94P6F6P68K0H64WRDSFKW),
308
329
  # ULID(2021-04-27 22:17:37.844 UTC: 01F4APHGSMFJZQTGXKZBFFBPJP),
309
- # ULID(2021-04-28 20:17:55.357 UTC: 01F4D231MXQJXAR8G2JZHEJNH3),
310
- # ULID(2021-04-30 07:18:54.307 UTC: 01F4GTA2332AS2VPHC4FMKC7R5),
311
- # ULID(2021-05-02 12:26:03.480 UTC: 01F4PGNXARG554Y3HYVBDW4T9S),
312
- # ULID(2021-04-29 09:52:15.107 UTC: 01F4EGP483ZX2747FQPWQNPPMW),
313
- # ULID(2021-04-29 03:18:24.152 UTC: 01F4DT4Z4RA0QV8WFQGRAG63EH),
314
- # ULID(2021-05-02 13:27:16.394 UTC: 01F4PM605ABF5SDVMEHBH8JJ9R)]
315
- ULID.sample(10, period: ulid1.to_time..ulid2.to_time)
330
+ # ULID(2021-04-28 20:17:55.357 UTC: 01F4D231MXQJXAR8G2JZHEJNH3)]
331
+ ULID.sample(5, period: ulid1.to_time..ulid2.to_time)
316
332
  #=>
317
333
  # [ULID(2021-04-29 06:44:41.513 UTC: 01F4E5YPD9XQ3MYXWK8ZJKY8SW),
318
334
  # ULID(2021-05-01 00:35:06.629 UTC: 01F4JNKD85SVK1EAEYSJGF53A2),
319
335
  # ULID(2021-05-02 12:45:28.408 UTC: 01F4PHSEYRG9BWBEWMRW1XE6WW),
320
336
  # ULID(2021-05-01 03:06:09.130 UTC: 01F4JY7ZBABCBMX16XH2Q4JW4W),
321
- # ULID(2021-04-29 21:38:58.109 UTC: 01F4FS45DX4049JEQK4W6TER6G),
322
- # ULID(2021-04-29 17:14:14.116 UTC: 01F4F9ZDQ449BE8BBZFEHYQWG2),
323
- # ULID(2021-04-30 16:18:08.205 UTC: 01F4HS5DPD1HWDVJNJ6YKJXKSK),
324
- # ULID(2021-04-30 10:31:33.602 UTC: 01F4H5ATF2A1CSQF0XV5NKZ288),
325
- # ULID(2021-04-28 16:49:06.484 UTC: 01F4CP4PDM214Q6H3KJP7DYJRR),
326
- # ULID(2021-04-28 15:05:06.808 UTC: 01F4CG68ZRST94T056KRZ5K9S4)]
337
+ # ULID(2021-04-29 21:38:58.109 UTC: 01F4FS45DX4049JEQK4W6TER6G)]
327
338
  ```
328
339
 
329
- ### ULID specification ambiguity around orthographical variants of the format
340
+ #### Variants of format
330
341
 
331
342
  I'm afraid so, we should consider [Current ULID spec](https://github.com/ulid/spec/tree/d0c7170df4517939e70129b4d6462cc162f2d5bf#universally-unique-lexicographically-sortable-identifier) has `orthographical variants of the format` possibilities.
332
343
 
@@ -354,7 +365,7 @@ ULID.normalized?('-olarz3-noekisv4rrff-q6ig5fav--') #=> false
354
365
  ULID.normalized?('01ARZ3N0EK1SV4RRFFQ61G5FAV') #=> true
355
366
  ```
356
367
 
357
- ### UUIDv4 converter for migration use-cases
368
+ #### UUIDv4 converter for migration use-cases
358
369
 
359
370
  `ULID.from_uuidv4` and `ULID#to_uuidv4` is the converter.
360
371
  The imported timestamp is meaningless. So ULID's benefit will lost.
@@ -442,7 +453,7 @@ The results are not something to be proud of.
442
453
 
443
454
  See structure at [examples/rbs_sandbox](https://github.com/kachick/ruby-ulid/tree/main/examples/rbs_sandbox)
444
455
 
445
- I have checked the behavior with [ruby/rbs@2.6.0](https://github.com/ruby/rbs) && [soutaro/steep@1.0.1](https://github.com/soutaro/steep) && [soutaro/steep-vscode](https://github.com/soutaro/steep-vscode).
456
+ I have checked the behavior with [ruby/rbs@2.6.0](https://github.com/ruby/rbs) + [soutaro/steep@1.0.1](https://github.com/soutaro/steep) + [soutaro/steep-vscode](https://github.com/soutaro/steep-vscode).
446
457
 
447
458
  * ![rbs overview](./assets/ulid-rbs-overview.png?raw=true.png)
448
459
  * ![rbs mix](./assets/ulid-rbs-mix.png?raw=true.png)
data/lib/ruby-ulid.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: us-ascii
2
2
  # frozen_string_literal: true
3
+ # shareable_constant_value: literal
3
4
 
4
5
  # Copyright (C) 2021 Kenichi Kamiya
5
6
 
@@ -1,5 +1,6 @@
1
1
  # coding: us-ascii
2
2
  # frozen_string_literal: true
3
+ # shareable_constant_value: literal
3
4
 
4
5
  # Copyright (C) 2021 Kenichi Kamiya
5
6
 
@@ -1,10 +1,13 @@
1
1
  # coding: us-ascii
2
2
  # frozen_string_literal: true
3
+ # shareable_constant_value: literal
3
4
 
4
5
  # Copyright (C) 2021 Kenichi Kamiya
5
6
 
6
7
  class ULID
7
8
  class MonotonicGenerator
9
+ # @note When use https://github.com/ko1/ractor-tvar might realize Ractor based thread safe monotonic generator.
10
+ # However it is a C extention, I'm pending to use it for now.
8
11
  include(MonitorMixin)
9
12
 
10
13
  # @dynamic prev
@@ -0,0 +1,12 @@
1
+ # coding: us-ascii
2
+ # frozen_string_literal: true
3
+
4
+ class ULID
5
+ min = parse('00000000000000000000000000').freeze
6
+ max = parse('7ZZZZZZZZZZZZZZZZZZZZZZZZZ').freeze
7
+
8
+ ractor_can_make_shareable_time = RUBY_VERSION >= '3.1'
9
+
10
+ MIN = ractor_can_make_shareable_time ? Ractor.make_shareable(min) : min
11
+ MAX = ractor_can_make_shareable_time ? Ractor.make_shareable(max) : max
12
+ end
data/lib/ulid/uuid.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: us-ascii
2
2
  # frozen_string_literal: true
3
+ # shareable_constant_value: literal
3
4
 
4
5
  # Copyright (C) 2021 Kenichi Kamiya
5
6
 
data/lib/ulid/version.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # coding: us-ascii
2
2
  # frozen_string_literal: true
3
+ # shareable_constant_value: literal
3
4
 
4
5
  class ULID
5
- VERSION = '0.3.0'
6
+ VERSION = '0.4.0'
6
7
  end
data/lib/ulid.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: us-ascii
2
2
  # frozen_string_literal: true
3
+ # shareable_constant_value: experimental_everything
3
4
 
4
5
  # Copyright (C) 2021 Kenichi Kamiya
5
6
 
@@ -42,8 +43,7 @@ class ULID
42
43
  STRICT_PATTERN_WITH_CROCKFORD_BASE32_SUBSET = /\A#{PATTERN_WITH_CROCKFORD_BASE32_SUBSET.source}\z/i.freeze
43
44
 
44
45
  # Optimized for `ULID.scan`, might be changed the definition with gathered `ULID.scan` spec changed.
45
- # This can't contain `\b` for considering UTF-8 (e.g. Japanese), so intentional `false negative` definition.
46
- SCANNING_PATTERN = /[0-7][#{CROCKFORD_BASE32_ENCODING_STRING}]{#{TIMESTAMP_ENCODED_LENGTH - 1}}[#{CROCKFORD_BASE32_ENCODING_STRING}]{#{RANDOMNESS_ENCODED_LENGTH}}/i.freeze
46
+ SCANNING_PATTERN = /\b[0-7][#{CROCKFORD_BASE32_ENCODING_STRING}]{#{TIMESTAMP_ENCODED_LENGTH - 1}}[#{CROCKFORD_BASE32_ENCODING_STRING}]{#{RANDOMNESS_ENCODED_LENGTH}}\b/i.freeze
47
47
 
48
48
  # Similar as Time#inspect since Ruby 2.7, however it is NOT same.
49
49
  # Time#inspect trancates needless digits. Keeping full milliseconds with "%3N" will fit for ULID.
@@ -83,7 +83,7 @@ class ULID
83
83
 
84
84
  RANDOM_INTEGER_GENERATOR = -> {
85
85
  SecureRandom.random_number(MAX_INTEGER)
86
- }
86
+ }.freeze
87
87
 
88
88
  # @param [Range<Time>, Range<nil>, Range[ULID], nil] period
89
89
  # @overload sample(number, period: nil)
@@ -231,9 +231,9 @@ class ULID
231
231
  # @api private
232
232
  # @param [Time] time
233
233
  # @return [Integer]
234
- private_class_method(def self.milliseconds_from_time(time)
234
+ private_class_method def self.milliseconds_from_time(time)
235
235
  (time.to_r * 1000).to_i
236
- end)
236
+ end
237
237
 
238
238
  # @api private
239
239
  # @param [Time, Integer] moment
@@ -250,9 +250,9 @@ class ULID
250
250
  end
251
251
 
252
252
  # @return [Integer]
253
- private_class_method(def self.reasonable_entropy
253
+ private_class_method def self.reasonable_entropy
254
254
  SecureRandom.random_number(MAX_ENTROPY)
255
- end)
255
+ end
256
256
 
257
257
  # @param [String, #to_str] string
258
258
  # @return [ULID]
@@ -316,7 +316,7 @@ class ULID
316
316
 
317
317
  # @param [BasicObject] object
318
318
  # @return [String]
319
- private_class_method(def self.safe_get_class_name(object)
319
+ private_class_method def self.safe_get_class_name(object)
320
320
  fallback = 'UnknownObject'
321
321
 
322
322
  # This class getter implementation used https://github.com/rspec/rspec-support/blob/4ad8392d0787a66f9c351d9cf6c7618e18b3d0f2/lib/rspec/support.rb#L83-L89 as a reference, thank you!
@@ -325,7 +325,7 @@ class ULID
325
325
  begin
326
326
  object.class
327
327
  rescue NoMethodError
328
- # steep can't correctly handle singeton class assign. See https://github.com/soutaro/steep/pull/586 for further detail
328
+ # steep can't correctly handle singleton class assign. See https://github.com/soutaro/steep/pull/586 for further detail
329
329
  # So this annotation is hack for the type infer.
330
330
  # @type var object: BasicObject
331
331
  # @type var singleton_class: untyped
@@ -341,7 +341,7 @@ class ULID
341
341
  else
342
342
  name || fallback
343
343
  end
344
- end)
344
+ end
345
345
 
346
346
  # @api private
347
347
  # @param [Integer] milliseconds
@@ -409,13 +409,26 @@ class ULID
409
409
  # @dynamic ==
410
410
  alias_method(:==, :eql?)
411
411
 
412
+ # Return `true` for same value of ULID, variant formats of strings, same Time in ULID precision(msec).
413
+ # Do not consider integer, octets and partial strings, then returns `false`.
414
+ #
412
415
  # @return [Boolean]
416
+ # @see .normalize
417
+ # @see .floor
413
418
  def ===(other)
414
419
  case other
415
420
  when ULID
416
421
  @integer == other.to_i
417
422
  when String
418
- to_s == other.upcase
423
+ begin
424
+ normalized = ULID.normalize(other)
425
+ rescue Exception
426
+ false
427
+ else
428
+ to_s == normalized
429
+ end
430
+ when Time
431
+ to_time == ULID.floor(other)
419
432
  else
420
433
  false
421
434
  end
@@ -546,10 +559,9 @@ end
546
559
  require_relative('ulid/version')
547
560
  require_relative('ulid/crockford_base32')
548
561
  require_relative('ulid/monotonic_generator')
562
+ require_relative('ulid/ractor_unshareable_constants')
549
563
 
550
564
  class ULID
551
- MIN = parse('00000000000000000000000000').freeze
552
- MAX = parse('7ZZZZZZZZZZZZZZZZZZZZZZZZZ').freeze
553
-
565
+ # Do not write as `ULID.private_constant` for avoiding YARD warnings `[warn]: in YARD::Handlers::Ruby::PrivateConstantHandler: Undocumentable private constants:`
554
566
  private_constant(:TIME_FORMAT_IN_INSPECT, :MIN, :MAX, :RANDOM_INTEGER_GENERATOR, :CROCKFORD_BASE32_ENCODING_STRING)
555
567
  end
data/sig/ulid.rbs CHANGED
@@ -292,30 +292,20 @@ class ULID < Object
292
292
  # ulid2 = ULID.parse('01F4PTVCSN9ZPFKYTY2DDJVRK4') #=> ULID(2021-05-02 15:23:48.917 UTC: 01F4PTVCSN9ZPFKYTY2DDJVRK4)
293
293
  # ulids = ULID.sample(1000, period: ulid1..ulid2)
294
294
  # ulids.uniq.size #=> 1000
295
- # ulids.take(10)
295
+ # ulids.take(5)
296
296
  # #=>
297
297
  # #[ULID(2021-05-02 06:57:19.954 UTC: 01F4NXW02JNB8H0J0TK48JD39X),
298
298
  # # ULID(2021-05-02 07:06:07.458 UTC: 01F4NYC372GVP7NS0YAYQGT4VZ),
299
299
  # # ULID(2021-05-01 06:16:35.791 UTC: 01F4K94P6F6P68K0H64WRDSFKW),
300
300
  # # ULID(2021-04-27 22:17:37.844 UTC: 01F4APHGSMFJZQTGXKZBFFBPJP),
301
- # # ULID(2021-04-28 20:17:55.357 UTC: 01F4D231MXQJXAR8G2JZHEJNH3),
302
- # # ULID(2021-04-30 07:18:54.307 UTC: 01F4GTA2332AS2VPHC4FMKC7R5),
303
- # # ULID(2021-05-02 12:26:03.480 UTC: 01F4PGNXARG554Y3HYVBDW4T9S),
304
- # # ULID(2021-04-29 09:52:15.107 UTC: 01F4EGP483ZX2747FQPWQNPPMW),
305
- # # ULID(2021-04-29 03:18:24.152 UTC: 01F4DT4Z4RA0QV8WFQGRAG63EH),
306
- # # ULID(2021-05-02 13:27:16.394 UTC: 01F4PM605ABF5SDVMEHBH8JJ9R)]
301
+ # # ULID(2021-04-28 20:17:55.357 UTC: 01F4D231MXQJXAR8G2JZHEJNH3)]
307
302
  # ULID.sample(10, period: ulid1.to_time..ulid2.to_time)
308
303
  # #=>
309
304
  # # [ULID(2021-04-29 06:44:41.513 UTC: 01F4E5YPD9XQ3MYXWK8ZJKY8SW),
310
305
  # # ULID(2021-05-01 00:35:06.629 UTC: 01F4JNKD85SVK1EAEYSJGF53A2),
311
306
  # # ULID(2021-05-02 12:45:28.408 UTC: 01F4PHSEYRG9BWBEWMRW1XE6WW),
312
307
  # # ULID(2021-05-01 03:06:09.130 UTC: 01F4JY7ZBABCBMX16XH2Q4JW4W),
313
- # # ULID(2021-04-29 21:38:58.109 UTC: 01F4FS45DX4049JEQK4W6TER6G),
314
- # # ULID(2021-04-29 17:14:14.116 UTC: 01F4F9ZDQ449BE8BBZFEHYQWG2),
315
- # # ULID(2021-04-30 16:18:08.205 UTC: 01F4HS5DPD1HWDVJNJ6YKJXKSK),
316
- # # ULID(2021-04-30 10:31:33.602 UTC: 01F4H5ATF2A1CSQF0XV5NKZ288),
317
- # # ULID(2021-04-28 16:49:06.484 UTC: 01F4CP4PDM214Q6H3KJP7DYJRR),
318
- # # ULID(2021-04-28 15:05:06.808 UTC: 01F4CG68ZRST94T056KRZ5K9S4)]
308
+ # # ULID(2021-04-29 21:38:58.109 UTC: 01F4FS45DX4049JEQK4W6TER6G)]
319
309
  # ```
320
310
  def self.sample: (?period: period) -> ULID
321
311
  | (Integer number, ?period: period?) -> Array[ULID]
@@ -436,9 +426,28 @@ class ULID < Object
436
426
  # ULID.parse('4NNB20D9C1ME2NGMTX51ERZJX0') == ULID.parse('4nnb20d9c1me2ngmtx51erzjx0')
437
427
  # #=> true
438
428
  # ```
439
- def eql?: (untyped other) -> bool
429
+ def eql?: (ULID other) -> bool
430
+ | (untyped other) -> false
440
431
  alias == eql?
441
- def ===: (untyped other) -> bool
432
+
433
+ # Return `true` for same value of ULID, variant formats of strings, same Time in ULID precision(msec).
434
+ # Do not consider integer, octets and partial strings, then returns `false`.
435
+ #
436
+ # ```ruby
437
+ # ulid = ULID.parse('01G6Z7Q4RSH97E6QHAC7VK19G2')
438
+ # ulid === ULID.parse(ulid.to_s)
439
+ # #=> true
440
+ # ulid === ulid.to_s.downcase
441
+ # #=> true
442
+ # ulid === ulid.to_time
443
+ # #=> true
444
+ # ulid === ulid.to_i
445
+ # #=> false
446
+ # ulid === ulid.next
447
+ # #=> false
448
+ # ```
449
+ def ===: (ULID | String | Time other) -> bool
450
+ | (untyped other) -> false
442
451
 
443
452
  # ```ruby
444
453
  # ulid = ULID.generate
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ulid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-22 00:00:00.000000000 Z
11
+ date: 2022-07-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " generator, monotonic generator, parser and manipulations for ULID
14
- (ruby/rbs signatures included)\n"
14
+ (RBS included)\n"
15
15
  email:
16
16
  - kachick1+ruby@gmail.com
17
17
  executables: []
@@ -24,6 +24,7 @@ files:
24
24
  - lib/ulid.rb
25
25
  - lib/ulid/crockford_base32.rb
26
26
  - lib/ulid/monotonic_generator.rb
27
+ - lib/ulid/ractor_unshareable_constants.rb
27
28
  - lib/ulid/uuid.rb
28
29
  - lib/ulid/version.rb
29
30
  - sig/ulid.rbs