hashid-rails 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +15 -0
- data/lib/hashid/rails/configuration.rb +2 -1
- data/lib/hashid/rails/version.rb +1 -1
- data/lib/hashid/rails.rb +5 -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: ff291b0a3ecd103ccc6af6971f85636cd06e0c3f
|
4
|
+
data.tar.gz: 99cddc687a989d82845d7d928a26d5e8f19b872b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ba2b51cab4a714ba1d5020095e742bac5569a2d2316282af29e5733d97a0cd723b47009368e08b426fe10378e09824a8448446487dfad0e95bd08be48392dd4
|
7
|
+
data.tar.gz: 851fd6b4a1f66a5baf332ec942852c2811e635888f79aefd7b438e36c0c6622b7f24cb49a547a2000f3acb77e1f7e20846a052f1ec8d7893512f78db88f9a0dc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -65,8 +65,23 @@ Hashid::Rails.configure do |config|
|
|
65
65
|
# config.alphabet is optional, hashids provides a default
|
66
66
|
# alphabet that consists of all characters [a-zA-Z0-9]
|
67
67
|
config.alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
68
|
+
|
69
|
+
# If your alphbet contains any numerals [0-9], then we recommend diabling the find method
|
70
|
+
#config.disable_find = true
|
68
71
|
end
|
69
72
|
```
|
73
|
+
### Disable Find Method
|
74
|
+
|
75
|
+
If your alphabet includes numerals (0-9) and if the ids in your database are the same length as your hashes, then there could be valid
|
76
|
+
hashids that are identical to valid ids. This ambiguity could lead the `find` method to behave unpredictably. Since `find` accepts both
|
77
|
+
hashids and ids, an input argument that is potentially both a valid hashid and id, will cause `find` to treat the argument as a hashid
|
78
|
+
in some cases, and as an id in others. This unpredictably is usually not desired and can lead to subtle bugs appearing at runtime
|
79
|
+
|
80
|
+
In order to avoid this problem, users can add `config.disable_find = true` to their initializer. This will disable the hashid
|
81
|
+
functionality of the `find` method and force `find` to only accept normal (unhashed) ids. Under this configuration, programmer
|
82
|
+
will need to use the `find_by_hashid` method when desiring to explicitly search by hashid.
|
83
|
+
|
84
|
+
It is recommended that `config.disable_find = true` be set when the alphabet contains any numerals.
|
70
85
|
|
71
86
|
## Development
|
72
87
|
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Hashid
|
2
2
|
module Rails
|
3
3
|
class Configuration
|
4
|
-
attr_accessor :secret, :length, :alphabet
|
4
|
+
attr_accessor :secret, :length, :alphabet, :disable_find
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@secret = ""
|
8
8
|
@length = 6
|
9
9
|
@alphabet = nil
|
10
|
+
@disable_find = false
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/hashid/rails/version.rb
CHANGED
data/lib/hashid/rails.rb
CHANGED
@@ -63,7 +63,11 @@ module Hashid
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def find(hashid)
|
66
|
-
model_reload?
|
66
|
+
if model_reload? || Hashid::Rails.configuration.disable_find
|
67
|
+
super(hashid)
|
68
|
+
else
|
69
|
+
super(decode_id(hashid) || hashid)
|
70
|
+
end
|
67
71
|
end
|
68
72
|
|
69
73
|
def find_by_hashid(hashid)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashid-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Cypret
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|