prefixed_ids 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/prefixed_ids/prefix_id.rb +6 -4
- data/lib/prefixed_ids/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73928771de7b068333b2db44b844d9018cd0a583067268374eafca46426c8bc8
|
4
|
+
data.tar.gz: fc5d49d74a69e210378c8c7ec2d980aa39fce0e61882a96207e4f03beb4ee2c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ddaffaaf511acab48e02dee0664a9d6310e24306e36792800e5afeba9e58b0c6a8e0413f2fd0da521d2e900d8dda2c5d8c8dea36b4a67b0b47566971620f28b
|
7
|
+
data.tar.gz: 5d2406555e427e660ddbe71a8c3c9448ab27e54acf0427f6e232c655224524173ed4492c6352a36be191a62b91652efbf1556c6588f26d836da853cc9da99152
|
@@ -13,7 +13,7 @@ module PrefixedIds
|
|
13
13
|
def encode(id)
|
14
14
|
return if id.nil?
|
15
15
|
|
16
|
-
@prefix + @delimiter + @hashids.encode(TOKEN
|
16
|
+
@prefix + @delimiter + @hashids.encode([TOKEN] + Array.wrap(id))
|
17
17
|
end
|
18
18
|
|
19
19
|
# decode returns an array
|
@@ -21,17 +21,19 @@ module PrefixedIds
|
|
21
21
|
fallback_value = fallback ? id : nil
|
22
22
|
_, id_without_prefix = PrefixedIds.split_id(id, @delimiter)
|
23
23
|
decoded_hashid = @hashids.decode(id_without_prefix)
|
24
|
-
|
24
|
+
|
25
|
+
if !valid?(decoded_hashid)
|
25
26
|
fallback_value
|
26
27
|
else
|
27
|
-
decoded_hashid
|
28
|
+
_, id, *composite = decoded_hashid
|
29
|
+
composite.empty? ? id : composite
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
private
|
32
34
|
|
33
35
|
def valid?(decoded_hashid)
|
34
|
-
decoded_hashid.size
|
36
|
+
decoded_hashid.size >= 2 && decoded_hashid.first == TOKEN
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
data/lib/prefixed_ids/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prefixed_ids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|