prefixed_ids 1.7.1 → 1.8.1

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
  SHA256:
3
- metadata.gz: 6a72c0361e99045f5e380aafa8e671be149ce14bdfb1bc83fb8520f72f4d63ac
4
- data.tar.gz: fe98952521f2b62e4e1bbce4d66fe8a1c6d2074ce61e07cdbfaec2abfd07ac81
3
+ metadata.gz: 4a8f6545b87098d1b31cc7b509e962f5ffb1e57ab21a883905440d565dd0bcc8
4
+ data.tar.gz: 9e8d4a6413d67a47c64983207ef9c18b9132320174eeb7d0020512330eb9165e
5
5
  SHA512:
6
- metadata.gz: 9386a5f418e0c547540e4589fde5633efe4aa61518f472d33f2e812de2140efe4d4cff0474153722e0dae4e6b5c6923a382a9883787ccc9fa5383573c672fd69
7
- data.tar.gz: 011ab4e58529325474cbbb6b2f09d0c17daa6118b4ecb2866dad4b10997e1b64234f33e9d306bbec97e150c209617d00ef5a041b9c46f96440a35327082ab0e0
6
+ metadata.gz: b158bb40a94f3a6a0fc131cb5b5e7bc462d8ee6d5c08c0b74e760ea5e52ee56180fd447a5a7fb2dbca07de8f3f4f8d09ea0fdfb8ee50c3a16849760c6c01cf74
7
+ data.tar.gz: 2cd81c409ee3ef5b258de3ccd1344bdcfa1677afe92c3fcece799d4ad2c758efc43990111ca584fc955d1dd558d2102f9f3f39fd058379132493389bf8148bb8
@@ -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, id)
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
- if fallback && !valid?(decoded_hashid)
24
+
25
+ if !valid?(decoded_hashid)
25
26
  fallback_value
26
27
  else
27
- decoded_hashid.last
28
+ _, *ids = decoded_hashid
29
+ (ids.size == 1) ? ids.first : ids
28
30
  end
29
31
  end
30
32
 
31
33
  private
32
34
 
33
35
  def valid?(decoded_hashid)
34
- decoded_hashid.size == 2 && decoded_hashid.first == TOKEN
36
+ decoded_hashid.size >= 2 && decoded_hashid.first == TOKEN
35
37
  end
36
38
  end
37
39
  end
@@ -1,3 +1,3 @@
1
1
  module PrefixedIds
2
- VERSION = "1.7.1"
2
+ VERSION = "1.8.1"
3
3
  end
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.7.1
4
+ version: 1.8.1
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-01 00:00:00.000000000 Z
11
+ date: 2024-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails