lite-uxid 1.5.1 → 1.5.2

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: 5c35d2426c2fffc91f8195a96c94ff26df0c41ffdb79041c5499952c93ccd240
4
- data.tar.gz: 5a72d11d4fc6d3cec87411a623d072dec4ba1f17b810814b15c543da3a512d7b
3
+ metadata.gz: d000996f6e79fc0122e86a88c034391d9853146de2af1e44a1da19234ad538b1
4
+ data.tar.gz: 932aa03aeb3f62c58cb96328d38d9bc97ca09cc15f5f9a617147464448a45856
5
5
  SHA512:
6
- metadata.gz: 0a84caf603e6393456ac15d30afaf23fda68eec1480997ce64a54339abefcfc5fadf1afe4fb505f6b3f54119188e3f3405e040771e4a76cc4cae3f8b7f842693
7
- data.tar.gz: 0d345ae245719fcfe669230925aee58feab58153c978c6089379cc750ae417325d98bd6b660aba695e2df85d540d88a543bfd5a11ce88556fb2ef835f81a860d
6
+ metadata.gz: 1241d664904c1db3b9008bbd70bfb509070dc7adab95313ab5cac6a859fafeb6254f902ab0664086163bfa6d5998643d7f74f059525206d9354214f5595767ac
7
+ data.tar.gz: 51df74a8df875bbe8e67179960953d6ab54f8f49c11ab5783e90e5c31f6b8e8022ecf1074439083341cbdf9c40dce070c102d29bb947dd148b362f1dabdfc6a6
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.5.2] - 2024-09-20
10
+ ### Changed
11
+ - Fixed nanoid of differing length error
12
+
9
13
  ## [1.5.1] - 2024-09-20
10
14
  ### Changed
11
15
  - Use after commit on create instead of after create
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-uxid (1.5.1)
4
+ lite-uxid (1.5.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -44,10 +44,6 @@ module Lite
44
44
  opts.delete(key) || Lite::Uxid.configuration.send(sym_key)
45
45
  end
46
46
 
47
- def coder_bytes
48
- @coder_bytes ||= SecureRandom.random_bytes(coder_size).bytes
49
- end
50
-
51
47
  def coder_charset
52
48
  @coder_charset ||= coder_value_for(:charset)
53
49
  end
@@ -5,13 +5,38 @@ module Lite
5
5
  class Nanoid < Base::Irreversible
6
6
 
7
7
  def encode
8
- uxid = (0...coder_size).each_with_object(+"") do |i, str|
9
- str << coder_charset[coder_bytes[i] & 63]
8
+ uxid = +""
9
+
10
+ loop do
11
+ cached_bytes = bytes
12
+
13
+ (0...step).each do |idx|
14
+ byte = cached_bytes[idx] & mask
15
+ char = byte && coder_charset[byte]
16
+ next unless char
17
+
18
+ uxid << char
19
+ return uxid if uxid.size == coder_size
20
+ end
10
21
  end
11
22
 
12
23
  "#{coder_prefix}#{uxid}"
13
24
  end
14
25
 
26
+ private
27
+
28
+ def bytes
29
+ SecureRandom.random_bytes(coder_size).bytes
30
+ end
31
+
32
+ def mask
33
+ @mask ||= (2 << (Math.log(coder_length - 1) / Math.log(2))) - 1
34
+ end
35
+
36
+ def step
37
+ @step = (1.6 * mask * coder_size / coder_length).ceil
38
+ end
39
+
15
40
  end
16
41
  end
17
42
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Uxid
5
5
 
6
- VERSION = "1.5.1"
6
+ VERSION = "1.5.2"
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-uxid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez