prefixed_ids 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/prefixed_ids/version.rb +1 -1
- data/lib/prefixed_ids.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16d022537d510bcdcea78b0923d63c446e1b5fa85a5de1498f5206d6c8e1a935
|
4
|
+
data.tar.gz: 9c4d0267908842cc93d498320628916a8ba966a72634730e6eeade8ab70ffa3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c6ea5a2cb678238a2ee0102459d40c4d1c89755d69eddbca34e8c54b68ce455f08dd35c07b2c3fe381ddb4528d3913a0b50190bd45457baa18d102ee2c72a69
|
7
|
+
data.tar.gz: 4743147c32367f459b0eced1fd7959ce36cfbc55061ae85e50a858ed0a46e0269bc25a0763dbed68d928af4ad84ccd8e3656c3c3759a0609b1627be5326a08b6
|
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
|
-
|
46
|
+
@user.to_param
|
45
47
|
```
|
46
48
|
|
47
49
|
If `to_param` override is disabled:
|
48
50
|
|
49
51
|
```ruby
|
50
|
-
|
52
|
+
@user.prefix_id
|
51
53
|
```
|
52
54
|
|
53
55
|
##### Query by Prefixed ID
|
data/lib/prefixed_ids/version.rb
CHANGED
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
|
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.6.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: 2023-05-
|
11
|
+
date: 2023-05-24 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.
|
111
|
+
rubygems_version: 3.4.13
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Prefixed IDs generates IDs with friendly prefixes for your models
|