active_uxid 1.0.10 → 1.0.11
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/lib/active_uxid.rb +3 -3
- data/lib/active_uxid/base.rb +11 -3
- data/lib/active_uxid/ulid.rb +3 -10
- data/lib/active_uxid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9562a3022031637a6274b83a1e2314c06bb15376
|
4
|
+
data.tar.gz: e9393cde490974f5929bd68ba32df0ef2b025dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bedd95ff15abb5b98db5a3539fef901f3584abe6434339e51ca0e8a9ca0a67f169e02bc7895baf0542d41b1b7c7dceff00ae0ab2bfb7a85221d54bb5d674660b
|
7
|
+
data.tar.gz: 8f77b5888cf9f60e887ab4a20374b10a6cad55c5f823c4a253398534dfd0ef334db2d2f02706607a97e60fc3597aa196035eca1c8925b81c52b1b264e13234a3
|
data/lib/active_uxid.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
%w[version configuration].each do |file_name|
|
3
|
+
%w[version configuration base].each do |file_name|
|
4
4
|
require "active_uxid/#{file_name}"
|
5
5
|
end
|
6
6
|
|
7
|
-
%w[
|
8
|
-
require "active_uxid/record/#{file_name}"
|
7
|
+
%w[hash ulid].each do |file_name|
|
8
|
+
require "active_uxid/record/#{file_name}"
|
9
9
|
require "active_uxid/#{file_name}"
|
10
10
|
end
|
11
11
|
|
data/lib/active_uxid/base.rb
CHANGED
@@ -3,9 +3,17 @@
|
|
3
3
|
module ActiveUxid
|
4
4
|
class Base
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize
|
7
|
+
@config = ActiveUxid.configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
%w[encoding_chars encoding_length encoding_salt].each do |setting|
|
11
|
+
define_method(setting) { @config.send(setting) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def encoding_base
|
15
|
+
encoding_chars.length
|
16
|
+
end
|
9
17
|
|
10
18
|
end
|
11
19
|
end
|
data/lib/active_uxid/ulid.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveUxid
|
4
|
-
class Ulid
|
5
|
-
|
6
|
-
ENCODING_CHARS ||= ActiveUxid.configuration.encoding_chars
|
7
|
-
ENCODING_LENGTH = ActiveUxid.configuration.encoding_length
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@encoding_length = ActiveUxid.configuration.encoding_length
|
11
|
-
end
|
4
|
+
class Ulid < ActiveUxid::Base
|
12
5
|
|
13
6
|
def self.encode
|
14
7
|
klass = new
|
@@ -16,9 +9,9 @@ module ActiveUxid
|
|
16
9
|
end
|
17
10
|
|
18
11
|
def uxid_encode
|
19
|
-
(1
|
12
|
+
(1..encoding_length).reduce('') do |str, num|
|
20
13
|
shift = 128 - 5 * num
|
21
|
-
"#{str}#{
|
14
|
+
"#{str}#{encoding_chars[(uxid_octect >> shift) & 0x1f]}"
|
22
15
|
end
|
23
16
|
end
|
24
17
|
|
data/lib/active_uxid/version.rb
CHANGED