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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53d72563690a2848294f1bdc7a42bdf820efa41e
4
- data.tar.gz: b99671e3614e0ecd8fa3590fc92a0ad131f43a5f
3
+ metadata.gz: 0d21bb49d06fca0323f9747b59f097e34149c991
4
+ data.tar.gz: f6a5405aba4cc97f3770722293f32210f56ddf63
5
5
  SHA512:
6
- metadata.gz: ef0248aaf4c2c85809b81137f6b60be9628d6249e846b67502822e6a7a1e4d30a292f8f95621e3b21fc75b50875ad690f9967d956accb3d27b6a62b59a89db68
7
- data.tar.gz: 7ef6798511f4da6d9e044b0e0756424d4df337e3bc25e3faf6b124aac03bbcbcaf9efbd0347a778f9965179b0ea9acc871d832b48115152b75a4aa6207cf27b0
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 hashid
48
+ def generate_hashid
46
49
  ::Hashids.new(
47
50
  salt,
48
51
  min_length
@@ -1,3 +1,3 @@
1
1
  module HashidsUri
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-15 00:00:00.000000000 Z
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord