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 +4 -4
- data/CHANGELOG.md +11 -5
- data/Gemfile.lock +1 -1
- data/README.md +13 -12
- data/benchmarks/compare.rb +2 -2
- data/lib/lite/uxid.rb +1 -1
- data/lib/lite/uxid/{hash.rb → hashid.rb} +1 -1
- data/lib/lite/uxid/record/{hash.rb → hashid.rb} +4 -4
- data/lib/lite/uxid/record/nanoid.rb +8 -1
- data/lib/lite/uxid/version.rb +1 -1
- data/lite-uxid.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe547bd3a8fdf44914843620a6cdc666e1b03bbac050011461978e576941a81e
|
4
|
+
data.tar.gz: ce9f35b1eeedb1fff9c49d95f5786198a1ab7ddde2edd7ba7f3611e3394e73ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4af9d9462065e6b115617b3eedff718cce01a2220efba39e646463b320e24fd7865dbdb02f653de45c98778e2b8c4687a5bedbd0d5fe04bc27ad25e52bcc2dc6
|
7
|
+
data.tar.gz: 2d55a27063cbd1a3273f8d1212c56a1145484aa4c97dfe4950809555d2ddcd24c121fee54eb169f775e88d5ce11bb53c75fecd794c026d0f67e9f37427c75cc5
|
data/CHANGELOG.md
CHANGED
@@ -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
|
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
|
29
|
-
- Changed
|
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
|
39
|
+
- Added Nanoid
|
34
40
|
|
35
41
|
## [1.0.1] - 2019-06-25
|
36
42
|
### Removed
|
37
|
-
- Remove unused
|
43
|
+
- Remove unused active_support dependency
|
38
44
|
|
39
45
|
## [1.0.0] - 2019-06-25
|
40
46
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](http://badge.fury.io/rb/lite-uxid)
|
4
4
|
[](https://travis-ci.org/drexed/lite-uxid)
|
5
5
|
|
6
|
-
Lite::Uxid is a library for generating or obfuscating Id's based on
|
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
|
-
* [
|
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
|
-
##
|
50
|
+
## Hashid
|
51
51
|
|
52
|
-
|
52
|
+
Hashid's are reversible and is the most performant generator.
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
Lite::Uxid::
|
56
|
-
Lite::Uxid::
|
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::
|
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
|
-
|
107
|
+
Using one of the mixins above provides a handy method to find records by uxid.
|
108
108
|
|
109
109
|
```ruby
|
110
|
-
User.
|
111
|
-
User.
|
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.
|
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 `
|
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
|
|
data/benchmarks/compare.rb
CHANGED
data/lib/lite/uxid.rb
CHANGED
@@ -5,7 +5,7 @@ require 'active_support'
|
|
5
5
|
module Lite
|
6
6
|
module Uxid
|
7
7
|
module Record
|
8
|
-
module
|
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::
|
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::
|
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::
|
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
|
-
|
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
|
data/lib/lite/uxid/version.rb
CHANGED
data/lite-uxid.gemspec
CHANGED
@@ -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
|
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.
|
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/
|
209
|
+
- lib/lite/uxid/hashid.rb
|
210
210
|
- lib/lite/uxid/nanoid.rb
|
211
|
-
- lib/lite/uxid/record/
|
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
|
239
|
+
summary: Generate or obfuscate Id's using different patterns
|
240
240
|
test_files: []
|