prefixed_ids 1.7.0 → 1.8.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
  SHA256:
3
- metadata.gz: 89b486c2c314140be222d50337f74c65b7e3168397bd55c76a7248c70a81fa08
4
- data.tar.gz: 568c49fbbf0ca7ce7a4137953cb12213ba898232a4e95451175065f311587b01
3
+ metadata.gz: 73928771de7b068333b2db44b844d9018cd0a583067268374eafca46426c8bc8
4
+ data.tar.gz: fc5d49d74a69e210378c8c7ec2d980aa39fce0e61882a96207e4f03beb4ee2c0
5
5
  SHA512:
6
- metadata.gz: 2b7cdc5be6e1f6923847ce68fb54f6cc095b7da0cd59ff909c7527fcdfb19b87c57ea8317d5809b63578ce72c3878c4df23db243c5364429e3aa3ca34ea05791
7
- data.tar.gz: '0872d0c35e310df40ab3aed3c3cb07d3f29a3599f165085081786a9829c74832e529a50c7fe37ea3051fc805c6974ea0dfb7a0beb31e66793f7b9f2d0885c842'
6
+ metadata.gz: 1ddaffaaf511acab48e02dee0664a9d6310e24306e36792800e5afeba9e58b0c6a8e0413f2fd0da521d2e900d8dda2c5d8c8dea36b4a67b0b47566971620f28b
7
+ data.tar.gz: 5d2406555e427e660ddbe71a8c3c9448ab27e54acf0427f6e232c655224524173ed4492c6352a36be191a62b91652efbf1556c6588f26d836da853cc9da99152
@@ -11,7 +11,9 @@ module PrefixedIds
11
11
  end
12
12
 
13
13
  def encode(id)
14
- @prefix + @delimiter + @hashids.encode(TOKEN, id)
14
+ return if id.nil?
15
+
16
+ @prefix + @delimiter + @hashids.encode([TOKEN] + Array.wrap(id))
15
17
  end
16
18
 
17
19
  # decode returns an array
@@ -19,17 +21,19 @@ module PrefixedIds
19
21
  fallback_value = fallback ? id : nil
20
22
  _, id_without_prefix = PrefixedIds.split_id(id, @delimiter)
21
23
  decoded_hashid = @hashids.decode(id_without_prefix)
22
- if fallback && !valid?(decoded_hashid)
24
+
25
+ if !valid?(decoded_hashid)
23
26
  fallback_value
24
27
  else
25
- decoded_hashid.last
28
+ _, id, *composite = decoded_hashid
29
+ composite.empty? ? id : composite
26
30
  end
27
31
  end
28
32
 
29
33
  private
30
34
 
31
35
  def valid?(decoded_hashid)
32
- decoded_hashid.size == 2 && decoded_hashid.first == TOKEN
36
+ decoded_hashid.size >= 2 && decoded_hashid.first == TOKEN
33
37
  end
34
38
  end
35
39
  end
@@ -1,3 +1,3 @@
1
1
  module PrefixedIds
2
- VERSION = "1.7.0"
2
+ VERSION = "1.8.0"
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.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-25 00:00:00.000000000 Z
11
+ date: 2024-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,7 +65,7 @@ metadata:
65
65
  homepage_uri: https://github.com/excid3/prefixed_ids
66
66
  source_code_uri: https://github.com/excid3/prefixed_ids
67
67
  changelog_uri: https://github.com/excid3/prefixed_ids
68
- post_install_message:
68
+ post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
71
71
  - lib
@@ -80,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.5.9
84
- signing_key:
83
+ rubygems_version: 3.5.13
84
+ signing_key:
85
85
  specification_version: 4
86
86
  summary: Prefixed IDs generates IDs with friendly prefixes for your models
87
87
  test_files: []