prefixed_ids 1.6.1 → 1.7.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: afa295f257c683531956a2cb9d576c15a17daa215917e053552a2debe8c5645c
4
- data.tar.gz: 9e232d13a6675324217539ea4b2320f1a406ade6762aacef552f66d33d780f42
3
+ metadata.gz: 89b486c2c314140be222d50337f74c65b7e3168397bd55c76a7248c70a81fa08
4
+ data.tar.gz: 568c49fbbf0ca7ce7a4137953cb12213ba898232a4e95451175065f311587b01
5
5
  SHA512:
6
- metadata.gz: 1a88c09cea33f417b70bb5022ddc6a64dcc0125b4ec13f657db0b99aab899c5d510cfe61afc5a72df559dd31152ae59771315686d3695189108ca11bb723c216
7
- data.tar.gz: 759d7c033de37807e08fef5f0c97731dfaddb8f8e0a718cfa8d78dea7fd8239955110d985065042e1a26d477bd18fb45bd9278e1f3e43e075db59c17860cc3fc
6
+ metadata.gz: 2b7cdc5be6e1f6923847ce68fb54f6cc095b7da0cd59ff909c7527fcdfb19b87c57ea8317d5809b63578ce72c3878c4df23db243c5364429e3aa3ca34ea05791
7
+ data.tar.gz: '0872d0c35e310df40ab3aed3c3cb07d3f29a3599f165085081786a9829c74832e529a50c7fe37ea3051fc805c6974ea0dfb7a0beb31e66793f7b9f2d0885c842'
data/README.md CHANGED
@@ -104,6 +104,26 @@ PrefixedIds.find("acct_2iAnOP0xGDYk6dpe")
104
104
  #=> #<Account>
105
105
  ```
106
106
 
107
+ ### Exists
108
+
109
+ You can check if a record exists by its prefixed ID:
110
+
111
+ ```ruby
112
+ User.exists?("user_5vJjbzXq9KrLEMm3")
113
+ #=> true
114
+ ```
115
+
116
+ If given anything other than a prefixed ID, or `override_exists` is set to false, it will fall back to its original `exists?` method.
117
+
118
+ ```ruby
119
+ class User < ApplicationRecord
120
+ has_prefix_id :user, override_exists: false
121
+ end
122
+
123
+ User.exists?("user_5vJjbzXq9KrLEMm3")
124
+ #=> false
125
+ ```
126
+
107
127
  ### Customizing Prefix IDs
108
128
 
109
129
  You can customize the prefix, length, and attribute name for PrefixedIds.
@@ -1,3 +1,3 @@
1
1
  module PrefixedIds
2
- VERSION = "1.6.1"
2
+ VERSION = "1.7.0"
3
3
  end
data/lib/prefixed_ids.rb CHANGED
@@ -38,10 +38,11 @@ module PrefixedIds
38
38
  end
39
39
 
40
40
  class_methods do
41
- def has_prefix_id(prefix, override_find: true, override_param: true, fallback: true, **options)
41
+ def has_prefix_id(prefix, override_find: true, override_param: true, override_exists: true, fallback: true, **options)
42
42
  include Attribute
43
43
  include Finder if override_find
44
44
  include ToParam if override_param
45
+ include Exists if override_exists
45
46
  self._prefix_id = PrefixId.new(self, prefix, **options)
46
47
  self._prefix_id_fallback = fallback
47
48
 
@@ -123,4 +124,18 @@ module PrefixedIds
123
124
  _prefix_id.encode(id)
124
125
  end
125
126
  end
127
+
128
+ module Exists
129
+ extend ActiveSupport::Concern
130
+
131
+ class_methods do
132
+ def exists?(id)
133
+ if _prefix_id.present? && id.is_a?(String)
134
+ super(_prefix_id.decode(id))
135
+ else
136
+ super
137
+ end
138
+ end
139
+ end
140
+ end
126
141
  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.6.1
4
+ version: 1.7.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: 2023-11-17 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,34 +44,6 @@ dependencies:
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.0.0
47
- - !ruby/object:Gem::Dependency
48
- name: standard
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- - !ruby/object:Gem::Dependency
62
- name: appraisal
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
47
  description: Prefixed IDs generates IDs with friendly prefixes for your models
76
48
  email:
77
49
  - excid3@gmail.com
@@ -93,7 +65,7 @@ metadata:
93
65
  homepage_uri: https://github.com/excid3/prefixed_ids
94
66
  source_code_uri: https://github.com/excid3/prefixed_ids
95
67
  changelog_uri: https://github.com/excid3/prefixed_ids
96
- post_install_message:
68
+ post_install_message:
97
69
  rdoc_options: []
98
70
  require_paths:
99
71
  - lib
@@ -108,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
80
  - !ruby/object:Gem::Version
109
81
  version: '0'
110
82
  requirements: []
111
- rubygems_version: 3.4.22
112
- signing_key:
83
+ rubygems_version: 3.5.9
84
+ signing_key:
113
85
  specification_version: 4
114
86
  summary: Prefixed IDs generates IDs with friendly prefixes for your models
115
87
  test_files: []