prefixed_ids 1.5.1 → 1.6.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: '0792b1628632ca08581a3e9c40214ce2eda85c22a024e84efb8864a99a9ba86f'
4
- data.tar.gz: ee3fa57136647eeb745af0b0863cc3de1ef386a297819851fcaf98039a35938a
3
+ metadata.gz: afa295f257c683531956a2cb9d576c15a17daa215917e053552a2debe8c5645c
4
+ data.tar.gz: 9e232d13a6675324217539ea4b2320f1a406ade6762aacef552f66d33d780f42
5
5
  SHA512:
6
- metadata.gz: 22fb046b0c3ea5cf81e52bb799777b898cb90ccdd66ac6c93c4c4ede0affa10514964f02b3486b5f132394d88996d77cf19887b4692a654014d8c736fd1978f3
7
- data.tar.gz: 7ab99d15f8d4840d894f470802f88e53398410e5370d06cbe6ca88fa619c6fca95d50cd9a2908a96096f2c177b70bcef0d7cb4143555e5fd41de42d194b2eac1
6
+ metadata.gz: 1a88c09cea33f417b70bb5022ddc6a64dcc0125b4ec13f657db0b99aab899c5d510cfe61afc5a72df559dd31152ae59771315686d3695189108ca11bb723c216
7
+ data.tar.gz: 759d7c033de37807e08fef5f0c97731dfaddb8f8e0a718cfa8d78dea7fd8239955110d985065042e1a26d477bd18fb45bd9278e1f3e43e075db59c17860cc3fc
data/README.md CHANGED
@@ -36,18 +36,20 @@ end
36
36
 
37
37
  This will generate a value like `user_1234abcd`.
38
38
 
39
+ Note: You should add `has_prefix_id` before associations because it overrides `has_many` to add prefix ID lookups.
40
+
39
41
  ##### Prefix ID Param
40
42
 
41
43
  To retrieve the prefix ID, simply call:
42
44
 
43
45
  ```ruby
44
- User.to_param
46
+ @user.to_param
45
47
  ```
46
48
 
47
49
  If `to_param` override is disabled:
48
50
 
49
51
  ```ruby
50
- User.prefix_id
52
+ @user.prefix_id
51
53
  ```
52
54
 
53
55
  ##### Query by Prefixed ID
@@ -1,3 +1,3 @@
1
1
  module PrefixedIds
2
- VERSION = "1.5.1"
2
+ VERSION = "1.6.1"
3
3
  end
data/lib/prefixed_ids.rb CHANGED
@@ -64,6 +64,14 @@ module PrefixedIds
64
64
  find_by!(id: _prefix_id.decode(id))
65
65
  end
66
66
 
67
+ def prefix_id(id)
68
+ _prefix_id.encode(id)
69
+ end
70
+
71
+ def prefix_ids(ids)
72
+ ids.map { |id| prefix_id(id) }
73
+ end
74
+
67
75
  def decode_prefix_id(id)
68
76
  _prefix_id.decode(id)
69
77
  end
@@ -83,14 +91,16 @@ module PrefixedIds
83
91
 
84
92
  class_methods do
85
93
  def find(*ids)
86
- prefix_ids = *ids.map do |id|
87
- # Skip if model doesn't use prefixed ids
88
- next id unless _prefix_id.present?
94
+ # Skip if model doesn't use prefixed ids
95
+ return super if _prefix_id.blank?
89
96
 
97
+ prefix_ids = ids.flatten.map do |id|
90
98
  prefix_id = _prefix_id.decode(id, fallback: _prefix_id_fallback)
91
99
  raise Error, "#{id} is not a valid prefix_id" if !_prefix_id_fallback && prefix_id.nil?
92
100
  prefix_id
93
101
  end
102
+ prefix_ids = [prefix_ids] if ids.first.is_a?(Array)
103
+
94
104
  super(*prefix_ids)
95
105
  end
96
106
 
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.5.1
4
+ version: 1.6.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: 2023-05-08 00:00:00.000000000 Z
11
+ date: 2023-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.4.12
111
+ rubygems_version: 3.4.22
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Prefixed IDs generates IDs with friendly prefixes for your models