ksuid 0.2.0 → 0.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 +6 -0
- data/README.md +4 -3
- data/ksuid.gemspec +1 -1
- data/lib/ksuid/base62.rb +6 -1
- data/lib/ksuid/utils.rb +30 -4
- data/lib/ksuid/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f717bc154ecc3919542742b7c927f62c924a8d4f73ec81be31f3ac3239d2b76b
|
|
4
|
+
data.tar.gz: e64581c8cd8cb4097fc0cd8fe869f3900cc61de735bb0ac36947143ae87fe611
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dfa9df01eb24b3ce510d38d673726e0bd6e0bda87e5716cdbff2bdd4cdeec129a1cc1a95c60c221e91202837e8a70ff3ec90421bc9a026b5af98038de10d6b06
|
|
7
|
+
data.tar.gz: ed5c2932989a25b83ef0b3004a546cd0b3b465a208cf374e46daeeb34080eaac626908b846af74b6183fe1b896c4aeec8ee38628b87b9c1d805ef1dc2b1d5c3a
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.3.0](https://github.com/michaelherold/ksuid/compare/v0.2.0...v0.3.0) - 2021-10-07
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- A utility function for converting from a hexidecimal-encoded string to a byte string. This is necessary to handle the default encoding of binary fields within PostgreSQL.
|
|
12
|
+
|
|
7
13
|
## [0.2.0](https://github.com/michaelherold/ksuid/compare/v0.1.0...v0.2.0) - 2020-11-11
|
|
8
14
|
|
|
9
15
|
### Added
|
data/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# KSUID for Ruby
|
|
2
2
|
|
|
3
|
-
[][actions]
|
|
4
4
|
[][test-coverage]
|
|
5
5
|
[][maintainability]
|
|
6
6
|
[][inch]
|
|
7
7
|
|
|
8
|
+
[actions]: https://github.com/michaelherold/ksuid-ruby/actions
|
|
8
9
|
[inch]: http://inch-ci.org/github/michaelherold/ksuid-ruby
|
|
9
10
|
[maintainability]: https://codeclimate.com/github/michaelherold/ksuid-ruby/maintainability
|
|
10
11
|
[test-coverage]: https://codeclimate.com/github/michaelherold/ksuid-ruby/test_coverage
|
|
11
|
-
[travis]: https://travis-ci.org/michaelherold/ksuid-ruby
|
|
12
12
|
|
|
13
13
|
ksuid is a Ruby library that can generate and parse [KSUIDs](https://github.com/segmentio/ksuid). The original readme for the Go version of KSUID does a great job of explaining what they are and how they should be used, so it is excerpted here.
|
|
14
14
|
|
|
@@ -215,10 +215,11 @@ So you’re interested in contributing to KSUID? Check out our [contributing gui
|
|
|
215
215
|
|
|
216
216
|
## Supported Ruby Versions
|
|
217
217
|
|
|
218
|
-
This library aims to support and is [tested against][
|
|
218
|
+
This library aims to support and is [tested against][actions] the following Ruby versions:
|
|
219
219
|
|
|
220
220
|
* Ruby 2.5
|
|
221
221
|
* Ruby 2.6
|
|
222
|
+
* Ruby 2.7
|
|
222
223
|
* JRuby 9.2
|
|
223
224
|
|
|
224
225
|
If something doesn't work on one of these versions, it's a bug.
|
data/ksuid.gemspec
CHANGED
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
|
6
6
|
spec.name = 'ksuid'
|
|
7
7
|
spec.version = KSUID::VERSION
|
|
8
8
|
spec.authors = ['Michael Herold']
|
|
9
|
-
spec.email = ['
|
|
9
|
+
spec.email = ['opensource@michaeljherold.com']
|
|
10
10
|
|
|
11
11
|
spec.summary = 'Ruby implementation of the K-Sortable Unique IDentifier'
|
|
12
12
|
spec.description = spec.summary
|
data/lib/ksuid/base62.rb
CHANGED
|
@@ -20,6 +20,11 @@ module KSUID
|
|
|
20
20
|
# @api private
|
|
21
21
|
BASE = CHARSET.size
|
|
22
22
|
|
|
23
|
+
# A matcher that checks whether a String has a character outside the charset
|
|
24
|
+
#
|
|
25
|
+
# @api private
|
|
26
|
+
MATCHER = /[^#{CHARSET}]/.freeze
|
|
27
|
+
|
|
23
28
|
# Checks whether a string is a base 62-compatible string
|
|
24
29
|
#
|
|
25
30
|
# @api public
|
|
@@ -30,7 +35,7 @@ module KSUID
|
|
|
30
35
|
# @param string [String] the string to check for compatibility
|
|
31
36
|
# @return [Boolean]
|
|
32
37
|
def self.compatible?(string)
|
|
33
|
-
string.each_char.all? { |char|
|
|
38
|
+
string.each_char.all? { |char| !MATCHER.match?(char) }
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
# Decodes a base 62-encoded string into an integer
|
data/lib/ksuid/utils.rb
CHANGED
|
@@ -5,7 +5,19 @@ module KSUID
|
|
|
5
5
|
#
|
|
6
6
|
# @api private
|
|
7
7
|
module Utils
|
|
8
|
-
#
|
|
8
|
+
# A regular expression for splitting bytes out of a "binary" string
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
# @return [Regexp] the splitter
|
|
12
|
+
BYTES = /.{8}/.freeze
|
|
13
|
+
|
|
14
|
+
# A regular expression for splitting a String into pairs of characters
|
|
15
|
+
#
|
|
16
|
+
# @api private
|
|
17
|
+
# @return [Regexp] the splitter
|
|
18
|
+
PAIRS = /.{2}/.freeze
|
|
19
|
+
|
|
20
|
+
# Converts a byte array into a byte string
|
|
9
21
|
#
|
|
10
22
|
# @param bytes [String] a byte string
|
|
11
23
|
# @return [Array<Integer>] an array of bytes from the byte string
|
|
@@ -13,6 +25,21 @@ module KSUID
|
|
|
13
25
|
bytes.pack('C*')
|
|
14
26
|
end
|
|
15
27
|
|
|
28
|
+
# Converts a hex string into a byte string
|
|
29
|
+
#
|
|
30
|
+
# @param hex [String] a hex-encoded KSUID
|
|
31
|
+
# @param bits [Integer] the expected number of bits for the result
|
|
32
|
+
# @return [String] the byte string
|
|
33
|
+
def self.byte_string_from_hex(hex, bits = 32)
|
|
34
|
+
byte_array =
|
|
35
|
+
hex
|
|
36
|
+
.rjust(bits, '0')
|
|
37
|
+
.scan(PAIRS)
|
|
38
|
+
.map { |bytes| bytes.to_i(16) }
|
|
39
|
+
|
|
40
|
+
byte_string_from_array(byte_array)
|
|
41
|
+
end
|
|
42
|
+
|
|
16
43
|
# Converts a byte string or byte array into a hex-encoded string
|
|
17
44
|
#
|
|
18
45
|
# @param bytes [String, Array<Integer>] the byte string or array
|
|
@@ -47,9 +74,8 @@ module KSUID
|
|
|
47
74
|
int
|
|
48
75
|
.to_s(2)
|
|
49
76
|
.rjust(bits, '0')
|
|
50
|
-
.
|
|
51
|
-
.
|
|
52
|
-
.map { |digits| digits.join.to_i(2) }
|
|
77
|
+
.scan(BYTES)
|
|
78
|
+
.map { |digits| digits.to_i(2) }
|
|
53
79
|
.pack("C#{bits / 8}")
|
|
54
80
|
end
|
|
55
81
|
end
|
data/lib/ksuid/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ksuid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Herold
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-10-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -26,7 +26,7 @@ dependencies:
|
|
|
26
26
|
version: '1.15'
|
|
27
27
|
description: Ruby implementation of the K-Sortable Unique IDentifier
|
|
28
28
|
email:
|
|
29
|
-
-
|
|
29
|
+
- opensource@michaeljherold.com
|
|
30
30
|
executables: []
|
|
31
31
|
extensions: []
|
|
32
32
|
extra_rdoc_files: []
|