lite-uxid 2.0.0 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 767645737040b210cc058a0a781f89751f447e991aa03c527f5d12b039d1980a
4
- data.tar.gz: 1c777db2675144f26b24ed2ec75d175c83f55d5ede9e83ab5d0d75ca2b76e692
3
+ metadata.gz: 7a5ffc2eb4b3088dfba64e17944b8da4e50b6daf1340e45dafb6ad9c98917bad
4
+ data.tar.gz: da4d9ac855493ca6556782375e775192e07ef4ecd8a8a90b7ed13a76160d6cd9
5
5
  SHA512:
6
- metadata.gz: 313da972f69d52e8951d552c3269500767e7fb80255de25c44d1bbe0d6497aaa3b0c398736b2e451d393ad0642446e298ebbad36a225528f010a96a8684f221e
7
- data.tar.gz: 61ce05436d5e2793164007f1b28edd28ea138c9efbf02f0a6ac6ef021708d3171b61c77e2811dfe9c65ef764b46d55713e6121eefd57d87a22cb10e80a9c0eef
6
+ metadata.gz: 94dd97afca7b4eaebb652c6f916211b605a002645eae9500e0cc2fac1f85b1b213447e3f67278e768150acaf82dde5a7a1360cf86fe5142cb365e5d480404422
7
+ data.tar.gz: b15bb1df870cf94356098e8c87542f44e034a64dced29ddc0d7ebe292d9ceeaeb457a956bab23b8f8fee40e1d3c4c40e605805386f78e4807bd15af809b9f1da
data/CHANGELOG.md CHANGED
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.0.2] - 2024-09-23
10
+ ### Added
11
+ - Prefixes to uuid and ulid
12
+ ### Changed
13
+ - Improve configuration template
14
+ - Improve hashid generation
15
+ - Improve specs
16
+ - Improve docs
17
+ ### Removed
18
+ - Hashid size option
19
+
20
+ ## [2.0.1] - 2024-09-23
21
+ ### Changed
22
+ - Renamed `Scatterid` to `Obfuscateid`
23
+ ### Removed
24
+ - Removed prefix option from obfuscateid
25
+
9
26
  ## [2.0.0] - 2024-09-23
10
27
  ### Added
11
28
  - Scatterid reversible lib
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-uxid (2.0.0)
4
+ lite-uxid (2.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -162,7 +162,7 @@ GEM
162
162
  concurrent-ruby (~> 1.0)
163
163
  unicode-display_width (2.6.0)
164
164
  useragent (0.16.10)
165
- webrick (1.8.1)
165
+ webrick (1.8.2)
166
166
  zeitwerk (2.6.18)
167
167
 
168
168
  PLATFORMS
data/README.md CHANGED
@@ -27,12 +27,14 @@ Or install it yourself as:
27
27
 
28
28
  * [Configuration](#configuration)
29
29
  * [Usage](#usage)
30
- * [Hashid](#hashid)
31
- * [NanoID](#nanoid)
32
- * [Scatterid](#scatterid)
33
- * [ULID](#ulid)
34
- * [UUID](#uuid)
35
30
  * [Options](#options)
31
+ * [Reversible](#reversible)
32
+ * [HashID](#hashid)
33
+ * [ObfuscateID](#obfuscateid)
34
+ * [Irreversible](#Irreversible)
35
+ * [NanoID](#nanoid)
36
+ * [ULID](#ulid)
37
+ * [UUID](#uuid)
36
38
  * [ActiveRecord](#active_record)
37
39
  * [Benchmarks](#benchmarks)
38
40
 
@@ -42,101 +44,112 @@ Or install it yourself as:
42
44
  `config/initalizers/lite_uxid.rb`
43
45
 
44
46
  ```ruby
45
- Lite::Uxid::ALPHANUMERIC = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
46
- Lite::Uxid::COCKFORDS_32 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
47
- Lite::Uxid::WEB_SAFE = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
48
-
49
47
  Lite::Uxid.configure do |config|
50
- config.hashid_charset = ALPHANUMERIC
48
+ # HashID
49
+ config.hashid_charset = Lite::Uxid::ALPHANUMERIC
51
50
  config.hashid_salt = 1_369_136
52
- config.hashid_size = 16
53
- config.nanoid_charset = WEB_SAFE
51
+
52
+ # NanoID
53
+ config.nanoid_charset = Lite::Uxid::WEB_SAFE
54
54
  config.nanoid_size = 21
55
- config.ulid_charset = COCKFORDS_32
55
+
56
+ # ObfuscatedID
57
+ config.obfuscateid_spin = 0
58
+
59
+ # ULID
60
+ config.ulid_charset = Lite::Uxid::COCKFORDS_32
56
61
  config.ulid_size = 26
62
+
63
+ # UUID
57
64
  config.uuid_version = 4
58
65
  end
59
66
  ```
60
67
 
61
68
  ## Usage
62
69
 
63
- #### Instance
70
+ ### Instance call
71
+
64
72
  ```ruby
65
73
  coder = Lite::Uxid::Reversible::Hashid.new(10, size: 12)
66
74
  coder.encode #=> '67wGI0'
67
75
  ```
68
76
 
69
- #### Class
77
+ ### Class call
70
78
  ```ruby
71
79
  Lite::Uxid::Reversible::Hashid.decode('67wGI0', size: 12) #=> 10
72
80
  ```
73
81
 
74
- ## HashID
82
+ ## Options
75
83
 
76
- [More information](https://hashids.org)
84
+ Local options can be passed to override global options.
77
85
 
78
86
  ```ruby
79
- Lite::Uxid::Reversible::Hashid.encode(10) #=> '1zWr1m0'
80
- Lite::Uxid::Reversible::Hashid.decode('1zWr1m0') #=> 10
87
+ Lite::Uxid::Irreversible::Ulid.encode(charset: 'abc123', size: 12) #=> 'a3b12c12c3ca'
81
88
  ```
82
89
 
83
- ## NanoID
84
-
85
- [More information](https://github.com/ai/nanoid)
90
+ Passable options are:
86
91
 
87
92
  ```ruby
88
- Lite::Uxid::Irreversible::Nanoid.encode #=> 'sMuNUa3Cegn6r5GRQ4Ij2'
93
+ {
94
+ charset: 'string', # Available for: hashid, nanoid, ulid
95
+ salt: 'string', # Available for: hashid
96
+ size: 'integer', # Available for: nanoid, ulid
97
+ spin: 'integer', # Available for: obfuscateid
98
+ version: 'integer', # Available for: uuid
99
+ prefix: 'string' # Available for: hashid, nanoid, ulid, uuid
100
+ }
89
101
  ```
90
102
 
91
- ## ScatterID
103
+ ## Reversible
104
+
105
+ ### HashID
92
106
 
93
- [More information](https://github.com/namick/scatter_swap)
107
+ - [More information](https://hashids.org)
94
108
 
95
109
  ```ruby
96
- Lite::Uxid::Reversible::Scatterid.encode(10) #=> '2056964183'
97
- Lite::Uxid::Reversible::Scatterid.decode('2056964183') #=> 10
110
+ Lite::Uxid::Reversible::Hashid.encode(10) #=> '7pau2oXSklq0'
111
+ Lite::Uxid::Reversible::Hashid.decode('7pau2oXSklq0') #=> 10
98
112
  ```
99
113
 
100
- ## ULID
114
+ ### NanoID
101
115
 
102
- [More information](https://github.com/ulid/spec)
116
+ - [More information](https://github.com/ai/nanoid)
103
117
 
104
118
  ```ruby
105
- Lite::Uxid::Irreversible::Ulid.encode #=> '01GJAY9KGR539EZF4QWYEJGSN7'
119
+ Lite::Uxid::Irreversible::Nanoid.encode #=> 'sMuNUa3Cegn6r5GRQ4Ij2'
106
120
  ```
107
121
 
108
- ## UUID
122
+ ## Irreversible
109
123
 
110
- Implements `v4` and `v7` of the specification. [More information](https://en.wikipedia.org/wiki/Universally_unique_identifier)
124
+ ### ObfuscateID
125
+
126
+ - [More information](https://github.com/namick/scatter_swap)
111
127
 
112
128
  ```ruby
113
- Lite::Uxid::Irreversible::Uuid.encode #=> '4376a67e-1189-44b3-a599-7f7566bf105b'
129
+ Lite::Uxid::Reversible::Obfuscateid.encode(10) #=> 2056964183
130
+ Lite::Uxid::Reversible::Obfuscateid.decode(2056964183) #=> 10
114
131
  ```
115
132
 
116
- ## Options
133
+ ### ULID
117
134
 
118
- Local options can be passed to override global options.
135
+ - [More information](https://github.com/ulid/spec)
119
136
 
120
137
  ```ruby
121
- Lite::Uxid::Irreversible::Ulid.encode(charset: 'abc123', size: 12) #=> 'a3b12c12c3ca'
138
+ Lite::Uxid::Irreversible::Ulid.encode #=> '01GJAY9KGR539EZF4QWYEJGSN7'
122
139
  ```
123
140
 
124
- Passable options are:
141
+ ### UUID
142
+
143
+ Implements `v4` and `v7` of the specification.
144
+ - [More information](https://en.wikipedia.org/wiki/Universally_unique_identifier)
125
145
 
126
146
  ```ruby
127
- {
128
- charset: 'string', # Available for: hashid, nanoid, ulid
129
- salt: 'string', # Available for: hashid
130
- size: 'integer', # Available for: hashid, nanoid, ulid
131
- spin: 'integer', # Available for: scatterid
132
- version: 'integer', # Available for: uuid
133
- prefix: 'string' # Available for: hashid, nanoid
134
- }
147
+ Lite::Uxid::Irreversible::Uuid.encode #=> '4376a67e-1189-44b3-a599-7f7566bf105b'
135
148
  ```
136
149
 
137
150
  ## ActiveRecord
138
151
 
139
- **Table**
152
+ ### Table
140
153
 
141
154
  Add the following attribute to all corresponding tables.
142
155
 
@@ -146,7 +159,7 @@ Add the following attribute to all corresponding tables.
146
159
  t.string :uxid, null: false, index: { unique: true }
147
160
  ```
148
161
 
149
- If using UUID and your database supports it:
162
+ If using UUID or ULID and your database supports it:
150
163
 
151
164
  ```ruby
152
165
  t.uuid :uxid, null: false, index: { unique: true }
@@ -156,80 +169,64 @@ t.uuid :uxid, null: false, index: { unique: true }
156
169
 
157
170
  `uxid` attribute will be automatically generated and applied when the record is created.
158
171
 
159
- #### HashID
172
+ ### Mixin
160
173
  ```ruby
161
174
  class User < ActiveRecord::Base
175
+ # Pick one:
162
176
  include Lite::Uxid::Record::Hashid
163
- end
164
- ```
165
-
166
- #### NanoID
167
- ```ruby
168
- class User < ActiveRecord::Base
169
177
  include Lite::Uxid::Record::Nanoid
170
- end
171
- ```
172
-
173
- #### ScatterID
174
- ```ruby
175
- class User < ActiveRecord::Base
176
- include Lite::Uxid::Record::Scatterid
177
- end
178
- ```
179
-
180
- #### ULID
181
- ```ruby
182
- class User < ActiveRecord::Base
178
+ include Lite::Uxid::Record::Obfuscateid
183
179
  include Lite::Uxid::Record::Ulid
184
- end
185
- ```
186
-
187
- #### UUID
188
- ```ruby
189
- class User < ActiveRecord::Base
190
180
  include Lite::Uxid::Record::Uuid
191
181
  end
192
182
  ```
193
183
 
194
- Add a prefix to `hashid` and `nanoid` record types by adding a `uxid_prefix` method.
184
+ HashID, NanoID, ULID, and UUID modules allow prefixing via the `uxid_prefix` method.
195
185
 
196
186
  ```ruby
197
187
  class User < ActiveRecord::Base
198
188
  include Lite::Uxid::Record::Hashid
199
189
 
200
190
  def uxid_prefix
201
- "sub_"
191
+ "usr_"
202
192
  end
203
193
  end
204
194
  ```
205
195
 
206
- **Usage**
196
+ Using the `hashid` and `nanoid` above provide handy methods to find records by uxid.
207
197
 
208
- Using one of the mixins above provides a handy method to find records by uxid.
209
-
210
- #### HashID methods
211
198
  ```ruby
212
199
  user = User.new
213
200
  user.id_to_uxid #=> Encodes the records id to uxid
214
201
  user.uxid_to_id #=> Decodes the records uxid to id
215
- ```
216
202
 
217
- #### Finder methods
218
- ```ruby
219
203
  User.find_by_uxid('x123') #=> Find record by uxid
220
204
  User.find_by_uxid!('x123') #=> Raises an ActiveRecord::RecordNotFound error if not found
221
205
  ```
222
206
 
223
207
  ## Benchmarks
224
208
 
225
- The classes ranked from fastest to slowest are `UUID`, `Hashid`, `Nanoid`, and `Ulid`.
209
+ The classes ranked from fastest to slowest are `UUID`, `HashID`, `NanoID`, `ULID`, and `ObfuscateID`. Here are the latest results:
226
210
 
227
- View how each compares by running the [benchmarks](https://github.com/drexed/lite-uxid/tree/master/benchmarks).
211
+ ```
212
+ Calculating -------------------------------------
213
+ Hashid 135.993k (± 2.9%) i/s (7.35 μs/i) - 681.588k in 5.016413s
214
+ Obfuscateid 30.702k (± 2.2%) i/s (32.57 μs/i) - 155.907k in 5.080592s
215
+ NanoID 99.327k (± 1.5%) i/s (10.07 μs/i) - 504.135k in 5.076630s
216
+ ULID 82.211k (± 2.3%) i/s (12.16 μs/i) - 418.455k in 5.092823s
217
+ UUID v4 237.629k (± 6.8%) i/s (4.21 μs/i) - 1.190M in 5.040477s
218
+ UUID v7 234.956k (±13.8%) i/s (4.26 μs/i) - 1.153M in 5.051057s
228
219
 
229
- #### Alternatives
220
+ Comparison:
221
+ UUID v4: 237629.0 i/s
222
+ UUID v7: 234955.9 i/s - same-ish: difference falls within error
223
+ Hashid: 135993.5 i/s - 1.75x slower
224
+ NanoID: 99327.3 i/s - 2.39x slower
225
+ ULID: 82210.7 i/s - 2.89x slower
226
+ Obfuscateid: 30702.0 i/s - 7.74x slower
227
+ ```
230
228
 
231
- Learn more about alternative functions and more advance hashing setups:
232
- [hashids.org](https://hashids.org)
229
+ View how each compares by running the [benchmarks](https://github.com/drexed/lite-uxid/tree/master/benchmarks).
233
230
 
234
231
  ## Development
235
232
 
@@ -6,24 +6,37 @@ require "benchmark/ips"
6
6
  require "lite/uxid"
7
7
 
8
8
  Benchmark.ips do |x|
9
- x.report("Hashid") do
9
+ x.report("HashID") do
10
10
  id = rand(1..1_000_000)
11
- Lite::Uxid::Hashid.encode(id)
11
+ Lite::Uxid::Reversible::Hashid.encode(id)
12
12
  end
13
13
 
14
+ x.report("ObfuscateID") do
15
+ id = rand(1..1_000_000)
16
+ Lite::Uxid::Reversible::Obfuscateid.encode(id)
17
+ end
18
+
19
+ # The irreversible examples include `rand` simulate
20
+ # the extra work just like reversible examples.
21
+
14
22
  x.report("NanoID") do
15
- _id = rand(1..1_000_000) # To simulate the extra work from `rand`
16
- Lite::Uxid::Nanoid.encode
23
+ _id = rand(1..1_000_000)
24
+ Lite::Uxid::Irreversible::Nanoid.encode
17
25
  end
18
26
 
19
27
  x.report("ULID") do
20
- _id = rand(1..1_000_000) # To simulate the extra work from `rand`
21
- Lite::Uxid::Ulid.encode
28
+ _id = rand(1..1_000_000)
29
+ Lite::Uxid::Irreversible::Ulid.encode
30
+ end
31
+
32
+ x.report("UUID v4") do
33
+ _id = rand(1..1_000_000)
34
+ Lite::Uxid::Irreversible::Uuid.encode
22
35
  end
23
36
 
24
- x.report("UUID") do
25
- _id = rand(1..1_000_000) # To simulate the extra work from `rand`
26
- Lite::Uxid::Uuid.encode
37
+ x.report("UUID v7") do
38
+ _id = rand(1..1_000_000)
39
+ Lite::Uxid::Irreversible::Uuid.encode(version: 7)
27
40
  end
28
41
 
29
42
  x.compare!
@@ -1,13 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Lite::Uxid.configure do |config|
4
- config.hashid_charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
5
- config.hashid_salt = 1_369_136
6
- config.hashid_size = 16
7
- config.nanoid_charset = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
8
- config.nanoid_size = 21
9
- config.scatterid_spin = 0
10
- config.ulid_charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
11
- config.ulid_size = 26
12
- config.uuid_version = 4
4
+ # HashID
5
+ # config.hashid_charset = Lite::Uxid::ALPHANUMERIC
6
+ # config.hashid_salt = 1_369_136
7
+
8
+ # NanoID
9
+ # config.nanoid_charset = Lite::Uxid::WEB_SAFE
10
+ # config.nanoid_size = 21
11
+
12
+ # ObfuscatedID
13
+ # config.obfuscateid_spin = 0
14
+
15
+ # ULID
16
+ # config.ulid_charset = Lite::Uxid::COCKFORDS_32
17
+ # config.ulid_size = 26
18
+
19
+ # UUID
20
+ # config.uuid_version = 4
13
21
  end
@@ -30,7 +30,7 @@ module Lite
30
30
  end
31
31
 
32
32
  def coder_length
33
- @coder_length ||= coder_charset.size
33
+ @coder_length ||= coder_charset.length
34
34
  end
35
35
 
36
36
  def coder_prefix
@@ -9,19 +9,18 @@ module Lite
9
9
 
10
10
  class Configuration
11
11
 
12
- attr_accessor :hashid_charset, :hashid_size, :hashid_salt,
12
+ attr_accessor :hashid_charset, :hashid_salt,
13
13
  :nanoid_charset, :nanoid_size,
14
- :scatterid_spin,
14
+ :obfuscateid_spin,
15
15
  :ulid_charset, :ulid_size,
16
16
  :uuid_version
17
17
 
18
18
  def initialize
19
19
  @hashid_charset = ALPHANUMERIC
20
20
  @hashid_salt = 1_369_136
21
- @hashid_size = 16
22
21
  @nanoid_charset = WEB_SAFE
23
22
  @nanoid_size = 21
24
- @scatterid_spin = 0
23
+ @obfuscateid_spin = 0
25
24
  @ulid_charset = COCKFORDS_32
26
25
  @ulid_size = 26
27
26
  @uuid_version = 4
@@ -18,7 +18,7 @@ module Lite
18
18
  pos -= 1
19
19
  end
20
20
 
21
- encoded_id
21
+ "#{coder_prefix}#{encoded_id}"
22
22
  end
23
23
 
24
24
  private
@@ -6,12 +6,15 @@ module Lite
6
6
  class Uuid < Base
7
7
 
8
8
  def encode
9
- case coder_version
10
- when 7
11
- SecureRandom.uuid_v7
12
- else
13
- SecureRandom.uuid
14
- end
9
+ encoded_id =
10
+ case coder_version
11
+ when 7
12
+ SecureRandom.uuid_v7
13
+ else
14
+ SecureRandom.uuid
15
+ end
16
+
17
+ "#{coder_prefix}#{encoded_id}"
15
18
  end
16
19
 
17
20
  end
@@ -43,7 +43,8 @@ module Lite
43
43
  end
44
44
 
45
45
  def uxid_prefix
46
- nil
46
+ # Define in your class to enable prefixing uxid.
47
+ # eg: "sub_" or "user_"
47
48
  end
48
49
 
49
50
  private
@@ -13,7 +13,8 @@ module Lite
13
13
  end
14
14
 
15
15
  def uxid_prefix
16
- nil
16
+ # Define in your class to enable prefixing uxid.
17
+ # eg: "sub_" or "user_"
17
18
  end
18
19
 
19
20
  private
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Uxid
5
5
  module Record
6
- module Scatterid
6
+ module Obfuscateid
7
7
 
8
8
  def self.included(base)
9
9
  base.extend ClassMethods
@@ -17,7 +17,7 @@ module Lite
17
17
  module ClassMethods
18
18
 
19
19
  def find_by_uxid(uxid)
20
- decoded_id = Lite::Uxid::Reversible::Scatterid.decode(uxid, prefix: new.uxid_prefix)
20
+ decoded_id = Lite::Uxid::Reversible::Obfuscateid.decode(uxid)
21
21
  find_by(id: decoded_id)
22
22
  end
23
23
 
@@ -33,17 +33,13 @@ module Lite
33
33
  def id_to_uxid
34
34
  return unless respond_to?(:uxid)
35
35
 
36
- Lite::Uxid::Reversible::Scatterid.encode(id, prefix: uxid_prefix)
36
+ Lite::Uxid::Reversible::Obfuscateid.encode(id)
37
37
  end
38
38
 
39
39
  def uxid_to_id
40
40
  return unless respond_to?(:uxid)
41
41
 
42
- Lite::Uxid::Reversible::Scatterid.decode(uxid, prefix: uxid_prefix)
43
- end
44
-
45
- def uxid_prefix
46
- nil
42
+ Lite::Uxid::Reversible::Obfuscateid.decode(uxid)
47
43
  end
48
44
 
49
45
  private
@@ -12,10 +12,15 @@ module Lite
12
12
  end
13
13
  end
14
14
 
15
+ def uxid_prefix
16
+ # Define in your class to enable prefixing uxid.
17
+ # eg: "sub_" or "user_"
18
+ end
19
+
15
20
  private
16
21
 
17
22
  def callback_generate_uxid!
18
- self.uxid = Lite::Uxid::Irreversible::Ulid.encode
23
+ self.uxid = Lite::Uxid::Irreversible::Ulid.encode(prefix: uxid_prefix)
19
24
  end
20
25
 
21
26
  end
@@ -12,10 +12,15 @@ module Lite
12
12
  end
13
13
  end
14
14
 
15
+ def uxid_prefix
16
+ # Define in your class to enable prefixing uxid.
17
+ # eg: "sub_" or "user_"
18
+ end
19
+
15
20
  private
16
21
 
17
22
  def callback_generate_uxid!
18
- self.uxid = Lite::Uxid::Irreversible::Uuid.encode
23
+ self.uxid = Lite::Uxid::Irreversible::Uuid.encode(prefix: uxid_prefix)
19
24
  end
20
25
 
21
26
  end
@@ -5,14 +5,16 @@ module Lite
5
5
  module Reversible
6
6
  class Hashid < Base
7
7
 
8
+ MASK = 48
9
+
8
10
  def encode
9
- encoded_id = encode_chars((id + coder_salt) << coder_size)
11
+ encoded_id = encode_chars((id + coder_salt) << MASK)
10
12
  "#{coder_prefix}#{encoded_id}"
11
13
  end
12
14
 
13
15
  def decode
14
16
  encoded_id = id.delete_prefix(coder_prefix.to_s)
15
- (decode_chars(encoded_id) >> coder_size) - coder_salt
17
+ (decode_chars(encoded_id) >> MASK) - coder_salt
16
18
  end
17
19
 
18
20
  private
@@ -34,7 +36,7 @@ module Lite
34
36
  def decode_chars(encoded_id)
35
37
  pos = 0
36
38
  num = 0
37
- len = encoded_id.size
39
+ len = encoded_id.length
38
40
  max = len - 1
39
41
 
40
42
  while pos < len
@@ -3,21 +3,18 @@
3
3
  module Lite
4
4
  module Uxid
5
5
  module Reversible
6
- class Scatterid < Base
6
+ class Obfuscateid < Base
7
7
 
8
8
  def encode
9
9
  swap
10
10
  scatter
11
-
12
- "#{coder_prefix}#{joined_array}"
11
+ result
13
12
  end
14
13
 
15
14
  def decode
16
- @id = id.delete_prefix(coder_prefix.to_s)
17
-
18
15
  unscatter
19
16
  unswap
20
- joined_array.to_i
17
+ result
21
18
  end
22
19
 
23
20
  private
@@ -30,8 +27,8 @@ module Lite
30
27
  @coder_array ||= zero_padded_id.chars.collect(&:to_i)
31
28
  end
32
29
 
33
- def joined_array
34
- coder_array.join
30
+ def result
31
+ coder_array.join.to_i
35
32
  end
36
33
 
37
34
  def swapper_map(index)
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Uxid
5
5
 
6
- VERSION = "2.0.0"
6
+ VERSION = "2.0.2"
7
7
 
8
8
  end
9
9
  end
data/lib/lite/uxid.rb CHANGED
@@ -12,9 +12,9 @@ require "lite/uxid/irreversible/ulid"
12
12
  require "lite/uxid/irreversible/uuid"
13
13
  require "lite/uxid/reversible/base"
14
14
  require "lite/uxid/reversible/hashid"
15
- require "lite/uxid/reversible/scatterid"
15
+ require "lite/uxid/reversible/obfuscateid"
16
16
  require "lite/uxid/record/hashid"
17
17
  require "lite/uxid/record/nanoid"
18
- require "lite/uxid/record/scatterid"
18
+ require "lite/uxid/record/obfuscateid"
19
19
  require "lite/uxid/record/ulid"
20
20
  require "lite/uxid/record/uuid"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-uxid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-23 00:00:00.000000000 Z
11
+ date: 2024-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -225,12 +225,12 @@ files:
225
225
  - lib/lite/uxid/irreversible/uuid.rb
226
226
  - lib/lite/uxid/record/hashid.rb
227
227
  - lib/lite/uxid/record/nanoid.rb
228
- - lib/lite/uxid/record/scatterid.rb
228
+ - lib/lite/uxid/record/obfuscateid.rb
229
229
  - lib/lite/uxid/record/ulid.rb
230
230
  - lib/lite/uxid/record/uuid.rb
231
231
  - lib/lite/uxid/reversible/base.rb
232
232
  - lib/lite/uxid/reversible/hashid.rb
233
- - lib/lite/uxid/reversible/scatterid.rb
233
+ - lib/lite/uxid/reversible/obfuscateid.rb
234
234
  - lib/lite/uxid/version.rb
235
235
  - lite-uxid.gemspec
236
236
  homepage: http://drexed.github.io/lite-uxid