hashid-rails 1.1.1 → 1.2.0
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 +4 -0
- data/README.md +2 -2
- data/lib/hashid/rails.rb +13 -8
- data/lib/hashid/rails/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: 507694ba57b2e4a2bcdfa90869828753f0cb30d1
|
4
|
+
data.tar.gz: 91496f73e9b29be5cb2a4c72693de1f60c545b08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 661591b2767fae3adc5556e7e6c78fe912cbad133fedcd4266ee1d2317fc82cd29afe6fdf9d2870b2f4ce41d3f4e89fa7d56c0cc23ea5eed20c475eb96460006
|
7
|
+
data.tar.gz: 01c86a260f13fa72a9a253175ff3728d583ee41a70fc2e1960546efe0f716994ef2c4c2b7abe59218745543c501542dcd2abf62f93e8b54fa037b32472eae0e1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.2.0 (2017-11-17)
|
4
|
+
- Fix regression where `find_by_hashid` and `find_by_hashid!` attempt to decode
|
5
|
+
values that are not hashids. ([#41](https://github.com/jcypret/hashid-rails/pull/41))
|
6
|
+
|
3
7
|
## 1.1.1 (2017-11-03)
|
4
8
|
- Fix eager loading and finding records through a parent. ([#39](https://github.com/jcypret/hashid-rails/pull/39))
|
5
9
|
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ be added or removed at any time.
|
|
18
18
|
Add this line to your application's Gemfile:
|
19
19
|
|
20
20
|
```ruby
|
21
|
-
gem 'hashid-rails'
|
21
|
+
gem 'hashid-rails', '~> 1.0'
|
22
22
|
```
|
23
23
|
|
24
24
|
And then execute:
|
@@ -30,7 +30,7 @@ $ bundle
|
|
30
30
|
Or install it yourself as:
|
31
31
|
|
32
32
|
```shell
|
33
|
-
$ gem install hashid-rails
|
33
|
+
$ gem install hashid-rails -v 1.0
|
34
34
|
```
|
35
35
|
|
36
36
|
## Basic Usage
|
data/lib/hashid/rails.rb
CHANGED
@@ -52,11 +52,14 @@ module Hashid
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
# @param ids [String, Integer, Array<Integer, String>] id(s) to decode.
|
56
|
+
# @param fallback [Boolean] indicates whether to return the passed in
|
57
|
+
# id(s) if unable to decode or if already decoded.
|
58
|
+
def decode_id(ids, fallback: false)
|
56
59
|
if ids.is_a?(Array)
|
57
|
-
ids.map { |id| hashid_decode(id) }
|
60
|
+
ids.map { |id| hashid_decode(id, fallback: fallback) }
|
58
61
|
else
|
59
|
-
hashid_decode(ids)
|
62
|
+
hashid_decode(ids, fallback: fallback)
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
@@ -67,18 +70,18 @@ module Hashid
|
|
67
70
|
uniq_ids = uniq_ids.first unless expects_array || uniq_ids.size > 1
|
68
71
|
|
69
72
|
if Hashid::Rails.configuration.override_find
|
70
|
-
super(decode_id(uniq_ids))
|
73
|
+
super(decode_id(uniq_ids, fallback: true))
|
71
74
|
else
|
72
75
|
super
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
79
|
def find_by_hashid(hashid)
|
77
|
-
find_by(id: decode_id(hashid))
|
80
|
+
find_by(id: decode_id(hashid, fallback: false))
|
78
81
|
end
|
79
82
|
|
80
83
|
def find_by_hashid!(hashid)
|
81
|
-
find_by!(id: decode_id(hashid))
|
84
|
+
find_by!(id: decode_id(hashid, fallback: false))
|
82
85
|
end
|
83
86
|
|
84
87
|
private
|
@@ -95,10 +98,12 @@ module Hashid
|
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
98
|
-
def hashid_decode(id)
|
101
|
+
def hashid_decode(id, fallback:)
|
99
102
|
decoded_hashid = hashids.decode(id.to_s)
|
103
|
+
fallback_value = fallback ? id : nil
|
104
|
+
|
100
105
|
if Hashid::Rails.configuration.sign_hashids
|
101
|
-
valid_hashid?(decoded_hashid) ? decoded_hashid.last :
|
106
|
+
valid_hashid?(decoded_hashid) ? decoded_hashid.last : fallback_value
|
102
107
|
else
|
103
108
|
decoded_hashid.first
|
104
109
|
end
|
data/lib/hashid/rails/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2017-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|