lite-uxid 2.0.0 → 2.0.1

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: 9078e4e13dc6877ed30a6a0028ad4327ff95d3056a5303f789137272e2bb0f12
4
+ data.tar.gz: c25e8acbb22ad4e4381bf9b07018eaf12daaf8e1d0123cee24f5fa9c8af8e87a
5
5
  SHA512:
6
- metadata.gz: 313da972f69d52e8951d552c3269500767e7fb80255de25c44d1bbe0d6497aaa3b0c398736b2e451d393ad0642446e298ebbad36a225528f010a96a8684f221e
7
- data.tar.gz: 61ce05436d5e2793164007f1b28edd28ea138c9efbf02f0a6ac6ef021708d3171b61c77e2811dfe9c65ef764b46d55713e6121eefd57d87a22cb10e80a9c0eef
6
+ metadata.gz: bd5d7ef2cd4c425fb798dea874a7f395e20e5514ca07fb807d673feb75187e8a236236bd7f833084983a820d71a05a7a27c80d72138a13f888fb5b088a4c869f
7
+ data.tar.gz: 24462c53958076c1435e1012f3608002d23fdb01b3d59d00ac9d7d78c81f8f1d91b3a80fcac78d9a6a9ce358d9db728af6dd6df3d6815037a1c7dfa25515ba3f
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.0.1] - 2024-09-23
10
+ ### Changed
11
+ - Renamed `Scatterid` to `Obfuscateid`
12
+ ### Removed
13
+ - Removed prefix option from obfuscateid
14
+
9
15
  ## [2.0.0] - 2024-09-23
10
16
  ### Added
11
17
  - 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.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -27,9 +27,9 @@ Or install it yourself as:
27
27
 
28
28
  * [Configuration](#configuration)
29
29
  * [Usage](#usage)
30
- * [Hashid](#hashid)
30
+ * [HashID](#hashid)
31
31
  * [NanoID](#nanoid)
32
- * [Scatterid](#scatterid)
32
+ * [ObfuscateID](#obfuscateid)
33
33
  * [ULID](#ulid)
34
34
  * [UUID](#uuid)
35
35
  * [Options](#options)
@@ -88,13 +88,13 @@ Lite::Uxid::Reversible::Hashid.decode('1zWr1m0') #=> 10
88
88
  Lite::Uxid::Irreversible::Nanoid.encode #=> 'sMuNUa3Cegn6r5GRQ4Ij2'
89
89
  ```
90
90
 
91
- ## ScatterID
91
+ ## ObfuscateID
92
92
 
93
93
  [More information](https://github.com/namick/scatter_swap)
94
94
 
95
95
  ```ruby
96
- Lite::Uxid::Reversible::Scatterid.encode(10) #=> '2056964183'
97
- Lite::Uxid::Reversible::Scatterid.decode('2056964183') #=> 10
96
+ Lite::Uxid::Reversible::Obfuscateid.encode(10) #=> '2056964183'
97
+ Lite::Uxid::Reversible::Obfuscateid.decode(2056964183) #=> 10
98
98
  ```
99
99
 
100
100
  ## ULID
@@ -128,7 +128,7 @@ Passable options are:
128
128
  charset: 'string', # Available for: hashid, nanoid, ulid
129
129
  salt: 'string', # Available for: hashid
130
130
  size: 'integer', # Available for: hashid, nanoid, ulid
131
- spin: 'integer', # Available for: scatterid
131
+ spin: 'integer', # Available for: obfuscateid
132
132
  version: 'integer', # Available for: uuid
133
133
  prefix: 'string' # Available for: hashid, nanoid
134
134
  }
@@ -159,34 +159,11 @@ t.uuid :uxid, null: false, index: { unique: true }
159
159
  #### HashID
160
160
  ```ruby
161
161
  class User < ActiveRecord::Base
162
+ # Pick one:
162
163
  include Lite::Uxid::Record::Hashid
163
- end
164
- ```
165
-
166
- #### NanoID
167
- ```ruby
168
- class User < ActiveRecord::Base
169
164
  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
165
+ include Lite::Uxid::Record::Obfuscateid
183
166
  include Lite::Uxid::Record::Ulid
184
- end
185
- ```
186
-
187
- #### UUID
188
- ```ruby
189
- class User < ActiveRecord::Base
190
167
  include Lite::Uxid::Record::Uuid
191
168
  end
192
169
  ```
@@ -198,16 +175,16 @@ class User < ActiveRecord::Base
198
175
  include Lite::Uxid::Record::Hashid
199
176
 
200
177
  def uxid_prefix
201
- "sub_"
178
+ "usr_"
202
179
  end
203
180
  end
204
181
  ```
205
182
 
206
183
  **Usage**
207
184
 
208
- Using one of the mixins above provides a handy method to find records by uxid.
185
+ Using the `hashid` and `nanoid` above provide handy methods to find records by uxid.
209
186
 
210
- #### HashID methods
187
+ #### Hashing methods
211
188
  ```ruby
212
189
  user = User.new
213
190
  user.id_to_uxid #=> Encodes the records id to uxid
@@ -222,15 +199,10 @@ User.find_by_uxid!('x123') #=> Raises an ActiveRecord::RecordNotFound error if n
222
199
 
223
200
  ## Benchmarks
224
201
 
225
- The classes ranked from fastest to slowest are `UUID`, `Hashid`, `Nanoid`, and `Ulid`.
202
+ The classes ranked from fastest to slowest are `UUID`, `HashID`, `NanoID`, `ULID`, and `ObfuscateID`.
226
203
 
227
204
  View how each compares by running the [benchmarks](https://github.com/drexed/lite-uxid/tree/master/benchmarks).
228
205
 
229
- #### Alternatives
230
-
231
- Learn more about alternative functions and more advance hashing setups:
232
- [hashids.org](https://hashids.org)
233
-
234
206
  ## Development
235
207
 
236
208
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -8,22 +8,30 @@ require "lite/uxid"
8
8
  Benchmark.ips do |x|
9
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
22
30
  end
23
31
 
24
32
  x.report("UUID") do
25
- _id = rand(1..1_000_000) # To simulate the extra work from `rand`
26
- Lite::Uxid::Uuid.encode
33
+ _id = rand(1..1_000_000)
34
+ Lite::Uxid::Irreversible::Uuid.encode
27
35
  end
28
36
 
29
37
  x.compare!
@@ -6,7 +6,7 @@ Lite::Uxid.configure do |config|
6
6
  config.hashid_size = 16
7
7
  config.nanoid_charset = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
8
8
  config.nanoid_size = 21
9
- config.scatterid_spin = 0
9
+ config.obfuscateid_spin = 0
10
10
  config.ulid_charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
11
11
  config.ulid_size = 26
12
12
  config.uuid_version = 4
@@ -11,7 +11,7 @@ module Lite
11
11
 
12
12
  attr_accessor :hashid_charset, :hashid_size, :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
 
@@ -21,7 +21,7 @@ module Lite
21
21
  @hashid_size = 16
22
22
  @nanoid_charset = WEB_SAFE
23
23
  @nanoid_size = 21
24
- @scatterid_spin = 0
24
+ @obfuscateid_spin = 0
25
25
  @ulid_charset = COCKFORDS_32
26
26
  @ulid_size = 26
27
27
  @uuid_version = 4
@@ -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
@@ -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.1"
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,7 +1,7 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
@@ -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