lite-uxid 1.0.6 → 1.0.7

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: b0f574e15cdd7048ec0fa01a581ffc9b87cc23280232bd65be19cecfde8f2bec
4
- data.tar.gz: 729e58e8c0c9bb0dd4946d864897a412503aac7501e79716fdd0664b589cf53b
3
+ metadata.gz: fe547bd3a8fdf44914843620a6cdc666e1b03bbac050011461978e576941a81e
4
+ data.tar.gz: ce9f35b1eeedb1fff9c49d95f5786198a1ab7ddde2edd7ba7f3611e3394e73ea
5
5
  SHA512:
6
- metadata.gz: 4ef8ffeaf8e8a1eebfd8e42b0a372613471de344947db842bb5016cc960cd4b0a9b907ae9f8542984ef87b5690ddf932de1d020c1997d02e653317df06f7842f
7
- data.tar.gz: 3a2a1be1875ee5e1d54d0547b954f749a3ba9b5cd494556fe8a38143c282c38500c333d280edbdd15a4b71cf789043705335a9476fc8dcdd39d43f4d1743bb36
6
+ metadata.gz: 4af9d9462065e6b115617b3eedff718cce01a2220efba39e646463b320e24fd7865dbdb02f653de45c98778e2b8c4687a5bedbd0d5fe04bc27ad25e52bcc2dc6
7
+ data.tar.gz: 2d55a27063cbd1a3273f8d1212c56a1145484aa4c97dfe4950809555d2ddcd24c121fee54eb169f775e88d5ce11bb53c75fecd794c026d0f67e9f37427c75cc5
@@ -6,11 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.7] - 2019-08-26
10
+ ### Added
11
+ - Added prevention of Nanoid collision when using with active_record
12
+ ### Changed
13
+ - Renamed Hash to Hashid
14
+
9
15
  ## [1.0.6] - 2019-08-26
10
16
  ### Changed
11
17
  - Improved how configuration works
12
18
  ### Removed
13
- - Remove activerecord and activesupport requirements that are already provided by Rails
19
+ - Remove active_record requirement that are already provided by Rails
14
20
 
15
21
  ## [1.0.5] - 2019-08-24
16
22
  ### Changed
@@ -25,16 +31,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
25
31
  - Added benchmarks
26
32
  ### Changed
27
33
  - Changed instance method names to match class names
28
- - Changed nanoid encoder to be faster
29
- - Changed ulid encoder to be faster
34
+ - Changed Nanoid encoder to be faster
35
+ - Changed Ulid encoder to be faster
30
36
 
31
37
  ## [1.0.2] - 2019-07-30
32
38
  ### Added
33
- - Added nanoid
39
+ - Added Nanoid
34
40
 
35
41
  ## [1.0.1] - 2019-06-25
36
42
  ### Removed
37
- - Remove unused activesupport dependency
43
+ - Remove unused active_support dependency
38
44
 
39
45
  ## [1.0.0] - 2019-06-25
40
46
  ### Added
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-uxid (1.0.6)
4
+ lite-uxid (1.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/lite-uxid.svg)](http://badge.fury.io/rb/lite-uxid)
4
4
  [![Build Status](https://travis-ci.org/drexed/lite-uxid.svg?branch=master)](https://travis-ci.org/drexed/lite-uxid)
5
5
 
6
- Lite::Uxid is a library for generating or obfuscating Id's based on Hash and ULID algorithms.
6
+ Lite::Uxid is a library for generating or obfuscating Id's based on different patterns.
7
7
  It's very useful to hide the number of resources in your database and protect against enumeration attacks.
8
8
 
9
9
  **NOTE:** If you are coming from `ActiveUxid`, please read the [port](#port) section.
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
  ## Table of Contents
28
28
 
29
29
  * [Configuration](#configuration)
30
- * [Hash](#hash)
30
+ * [Hashid](#hashid)
31
31
  * [NanoID](#nanoid)
32
32
  * [ULID](#ulid)
33
33
  * [ActiveRecord](#active_record)
@@ -47,13 +47,13 @@ Lite::Uxid.configure do |config|
47
47
  end
48
48
  ```
49
49
 
50
- ## Hash
50
+ ## Hashid
51
51
 
52
- Hash ID's are reversible and is the most performant generator.
52
+ Hashid's are reversible and is the most performant generator.
53
53
 
54
54
  ```ruby
55
- Lite::Uxid::Hash.encode(10) #=> 'q5D8inm0'
56
- Lite::Uxid::Hash.decode('q5D8inm0') #=> 10
55
+ Lite::Uxid::Hashid.encode(10) #=> 'q5D8inm0'
56
+ Lite::Uxid::Hashid.decode('q5D8inm0') #=> 10
57
57
  ```
58
58
 
59
59
  ## NanoID
@@ -90,7 +90,7 @@ All `nanoid` and `uxid` attributes will be automatically generated and applied w
90
90
 
91
91
  ```ruby
92
92
  class User < ActiveRecord::Base
93
- include Lite::Uxid::Record::Hash
93
+ include Lite::Uxid::Record::Hashid
94
94
 
95
95
  # - or -
96
96
 
@@ -104,19 +104,20 @@ end
104
104
 
105
105
  **Usage**
106
106
 
107
- The following methods are for Hash based Uxid's.
107
+ Using one of the mixins above provides a handy method to find records by uxid.
108
108
 
109
109
  ```ruby
110
- User.find_by_ulid('x123') #=> Find record by uxid
111
- User.find_by_ulid!('x123') #=> Raises an ActiveRecord::RecordNotFound error if not found
110
+ User.find_by_uxid('x123') #=> Find record by uxid
111
+ User.find_by_uxid!('x123') #=> Raises an ActiveRecord::RecordNotFound error if not found
112
112
 
113
+ # The following method is for Hashid based Uxid's.
113
114
  user = User.new
114
- user.hash_to_id #=> Decodes the records uxid to id (only for Hash based Id's)
115
+ user.uxid_to_id #=> Decodes the records uxid to id (only for Hashid based Id's)
115
116
  ```
116
117
 
117
118
  ## Benchmarks
118
119
 
119
- The classes ranked from fastest to slowest are `Hash`, `Nanoid`, and `Ulid`.
120
+ The classes ranked from fastest to slowest are `Hashid`, `Nanoid`, and `Ulid`.
120
121
 
121
122
  View how each compares by running the [benchmarks](https://github.com/drexed/lite-uxid/tree/master/benchmarks).
122
123
 
@@ -6,8 +6,8 @@ require 'benchmark/ips'
6
6
  require 'lite/uxid'
7
7
 
8
8
  Benchmark.ips do |x|
9
- x.report('Hash') do
10
- Lite::Uxid::Hash.encode(rand(1..1_000_000))
9
+ x.report('Hashid') do
10
+ Lite::Uxid::Hashid.encode(rand(1..1_000_000))
11
11
  end
12
12
 
13
13
  x.report('NanoID') do
@@ -4,7 +4,7 @@
4
4
  require "lite/uxid/#{name}"
5
5
  end
6
6
 
7
- %w[hash nanoid ulid].each do |name|
7
+ %w[hashid nanoid ulid].each do |name|
8
8
  require "lite/uxid/record/#{name}"
9
9
  require "lite/uxid/#{name}"
10
10
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lite
4
4
  module Uxid
5
- class Hash < Lite::Uxid::Base
5
+ class Hashid < Lite::Uxid::Base
6
6
 
7
7
  def initialize(id)
8
8
  @id = id
@@ -5,7 +5,7 @@ require 'active_support'
5
5
  module Lite
6
6
  module Uxid
7
7
  module Record
8
- module Hash
8
+ module Hashid
9
9
 
10
10
  extend ActiveSupport::Concern
11
11
 
@@ -15,7 +15,7 @@ module Lite
15
15
 
16
16
  class_methods do
17
17
  def find_by_uxid(uxid)
18
- decoded_id = Lite::Uxid::Hash.decode(uxid)
18
+ decoded_id = Lite::Uxid::Hashid.decode(uxid)
19
19
  find_by(id: decoded_id)
20
20
  end
21
21
 
@@ -30,13 +30,13 @@ module Lite
30
30
  def uxid_to_id
31
31
  return unless respond_to?(:uxid)
32
32
 
33
- Lite::Uxid::Hash.decode(uxid)
33
+ Lite::Uxid::Hashid.decode(uxid)
34
34
  end
35
35
 
36
36
  private
37
37
 
38
38
  def callback_generate_uxid!
39
- hash = Lite::Uxid::Hash.encode(id)
39
+ hash = Lite::Uxid::Hashid.encode(id)
40
40
  update_column(:uxid, hash)
41
41
  end
42
42
 
@@ -29,7 +29,14 @@ module Lite
29
29
  private
30
30
 
31
31
  def callback_generate_uxid!
32
- self.uxid = Lite::Uxid::Nanoid.encode
32
+ random_nanoid = nil
33
+
34
+ loop do
35
+ random_nanoid = Lite::Uxid::Nanoid.encode
36
+ break unless self.class.exists?(uxid: random_nanoid)
37
+ end
38
+
39
+ self.uxid = random_nanoid
33
40
  end
34
41
 
35
42
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Uxid
5
5
 
6
- VERSION ||= '1.0.6'
6
+ VERSION ||= '1.0.7'
7
7
 
8
8
  end
9
9
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Juan Gomez']
11
11
  spec.email = %w[j.gomez@drexed.com]
12
12
 
13
- spec.summary = "Generate or obfuscate Hash or ULID based Id's"
13
+ spec.summary = "Generate or obfuscate Id's using different patterns"
14
14
  spec.homepage = 'http://drexed.github.io/lite-uxid'
15
15
  spec.license = 'MIT'
16
16
 
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.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
@@ -206,9 +206,9 @@ files:
206
206
  - lib/lite/uxid.rb
207
207
  - lib/lite/uxid/base.rb
208
208
  - lib/lite/uxid/configuration.rb
209
- - lib/lite/uxid/hash.rb
209
+ - lib/lite/uxid/hashid.rb
210
210
  - lib/lite/uxid/nanoid.rb
211
- - lib/lite/uxid/record/hash.rb
211
+ - lib/lite/uxid/record/hashid.rb
212
212
  - lib/lite/uxid/record/nanoid.rb
213
213
  - lib/lite/uxid/record/ulid.rb
214
214
  - lib/lite/uxid/ulid.rb
@@ -236,5 +236,5 @@ requirements: []
236
236
  rubygems_version: 3.0.4
237
237
  signing_key:
238
238
  specification_version: 4
239
- summary: Generate or obfuscate Hash or ULID based Id's
239
+ summary: Generate or obfuscate Id's using different patterns
240
240
  test_files: []