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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fe325595eeafbc4188f0913be0ac17741e189aa
4
- data.tar.gz: b4185d19550070bcf9c0f39b68879143ac63f573
3
+ metadata.gz: ff291b0a3ecd103ccc6af6971f85636cd06e0c3f
4
+ data.tar.gz: 99cddc687a989d82845d7d928a26d5e8f19b872b
5
5
  SHA512:
6
- metadata.gz: df5fe6370f8361bc180b47af9786012639d5d84a7bebaf921c4da895f54f6bb72cf8193912a82cd7e0d7e00d1fbcd7d8a67be1909d3a905e7536b9596101ad2b
7
- data.tar.gz: 83b1355d0319263be80bf7e6e6138800a803fab8eb84114650f03b55b0552a8b55297df579c3b87cfae257b244f335f999fb04c6707bfea8c395cc26ef37b63c
6
+ metadata.gz: 2ba2b51cab4a714ba1d5020095e742bac5569a2d2316282af29e5733d97a0cd723b47009368e08b426fe10378e09824a8448446487dfad0e95bd08be48392dd4
7
+ data.tar.gz: 851fd6b4a1f66a5baf332ec942852c2811e635888f79aefd7b438e36c0c6622b7f24cb49a547a2000f3acb77e1f7e20846a052f1ec8d7893512f78db88f9a0dc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 (2017-02-15)
4
+ - Add configuration option to disable overriding default `find` (#22).
5
+
3
6
  ## 0.6.0 (2017-01-07)
4
7
  - Add Rubocop and adjust styles to be consistent.
5
8
  - Fix issue where finding multiple non-hashids returns an array of nils.
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
@@ -1,5 +1,5 @@
1
1
  module Hashid
2
2
  module Rails
3
- VERSION = "0.6.0".freeze
3
+ VERSION = "0.7.0".freeze
4
4
  end
5
5
  end
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? ? super(hashid) : super(decode_id(hashid) || hashid)
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.6.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-01-08 00:00:00.000000000 Z
11
+ date: 2017-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler