hashids_uri 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/hashids_uri.rb +4 -1
- data/lib/hashids_uri/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d21bb49d06fca0323f9747b59f097e34149c991
|
4
|
+
data.tar.gz: f6a5405aba4cc97f3770722293f32210f56ddf63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9c736a92705205bf38666a346690693eb9e509dc5dc26fa9fba55c6850ec2acc831a8c8523ecf5d2f4061827336b9acd94b8b721aad4813d031327e31cfc88d
|
7
|
+
data.tar.gz: 6e00a8cf0f9d0340761140af0d7c1da2aac27d3fb149b21bcdbdabe0ea085f068cc5bef1d4430aecea739a8bced107ccab2b17db308ae731c779d9e0d272385f
|
data/README.md
CHANGED
@@ -37,6 +37,11 @@ def User < ActiveRecord::Base
|
|
37
37
|
end
|
38
38
|
```
|
39
39
|
|
40
|
+
You will also need to create a database column called `hashid`, this was added
|
41
|
+
to improve performance:
|
42
|
+
|
43
|
+
$ bin/rails g add_hashid_to_users hashid:string:uniq
|
44
|
+
|
40
45
|
By default the underlying Hashids gem does not provide a unique salt when creating a hash, this will lead to the same hash for each model with the same ID. If you require a unique hash you can provide a salt when initializing HashidsUri.
|
41
46
|
|
42
47
|
```ruby
|
data/lib/hashids_uri.rb
CHANGED
@@ -14,6 +14,9 @@ module ActiveRecord
|
|
14
14
|
|
15
15
|
self.salt = options.fetch(:salt, '')
|
16
16
|
self.min_length = options.fetch(:min_length, 6)
|
17
|
+
|
18
|
+
define_method(:hashid) { read_attribute(:hashid) || generate_hashid }
|
19
|
+
after_create { update_attribute(:hashid, generate_hashid) unless hashid? }
|
17
20
|
end
|
18
21
|
|
19
22
|
def find_by_hash(hash)
|
@@ -42,7 +45,7 @@ module ActiveRecord
|
|
42
45
|
self.class.min_length
|
43
46
|
end
|
44
47
|
|
45
|
-
def
|
48
|
+
def generate_hashid
|
46
49
|
::Hashids.new(
|
47
50
|
salt,
|
48
51
|
min_length
|
data/lib/hashids_uri/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashids_uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Draper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|