paranoia 2.6.3 → 2.6.4

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: 6f7493c138657c99cbb4eca5ed981c6bfac2400f18d34ad7fda9266ad672c39c
4
- data.tar.gz: 4397c1ac47d8b67fb3db3a084bdaea2fec4d2ebe5c475c99b2914563e3011ae9
3
+ metadata.gz: 1c181b837c0b9148cea47aaac1d370b142037943ee9e115ca14c2c1ae794c384
4
+ data.tar.gz: 9bbd8a2b61fe1a68871f11af0673ddb9ae83ae3bb51ff887354f758d300cac11
5
5
  SHA512:
6
- metadata.gz: 5acd851f9180575136c06b5e6c44db7a7b53462771d77d722790062ca7e4e2482e2938f35471b54d472f68c1d92b372334b3c269931d997bdd4562c5904ea800
7
- data.tar.gz: 2efed9b375277b7c1d066499323fe23af8f1af9c139389c45f2688eeb231da1ab8584cd061ba49f66130af4751263eb52458d8d2f68ae1057765437cdc320811
6
+ metadata.gz: f8824844107b4cd59840c174b99a2ce7f92ed03762ec5fffcf912f26be59a5fe52480a93b66515631b608ee6c575e664444b8b48414e3efef757ef42250adf32
7
+ data.tar.gz: cf0fc54e5a6b8906ad3cbf864c3a40250b6e7f9a2775f911e33e4ae420a5354c0ddde54936e033b9fc15be0e0dabc58b5db3a70a9b0f17b2ba610d1dfb628e5e
@@ -45,7 +45,7 @@ jobs:
45
45
  env:
46
46
  RAILS: ${{ matrix.rails }}
47
47
  steps:
48
- - uses: actions/checkout@v2
48
+ - uses: actions/checkout@v4
49
49
  - uses: ruby/setup-ruby@v1
50
50
  with:
51
51
  ruby-version: ${{ matrix.ruby }}
data/CHANGELOG.md CHANGED
@@ -1,22 +1,32 @@
1
1
  # paranoia Changelog
2
2
 
3
- ## 2.6.3
3
+ ## 2.6.4 - July 20, 2024
4
4
 
5
- * [#548](https://github.com/rubysherpas/paranoia/pull/441) Add support for [Rails 7.1](https://github.com/rails/rails/releases/tag/v7.1.0) (#441)
6
-
5
+ Add support for [Rails 7.2](https://github.com/rails/rails/releases/tag/v7.2.0)
6
+
7
+ * [#554](https://github.com/rubysherpas/paranoia/pull/554) Support prebuilt counter cache association list (#554)
8
+ [Joé Dupuis](https://github.com/JoeDupuis)
9
+ * [#551](https://github.com/rubysherpas/paranoia/pull/551) Fix: restore has_one with scope (#551)
10
+ [Paweł Charyło](https://github.com/zygzagZ)
11
+ * [#555](https://github.com/rubysherpas/paranoia/pull/555) 📝 Add Yard documentation for Paranoia::Query (#555)
12
+ [Clément Prod'homme](https://github.com/cprodhomme)
13
+
14
+ ## 2.6.3 - Oct 12, 2023
15
+
16
+ * [#548](https://github.com/rubysherpas/paranoia/pull/548) Add support for [Rails 7.1](https://github.com/rails/rails/releases/tag/v7.1.0) (#548)
7
17
  [Indyarocks](https://github.com/indyarocks)
8
18
 
9
- ## 2.6.2
19
+ ## 2.6.2 - Jun 6, 2023
10
20
 
11
21
  * [#441](https://github.com/rubysherpas/paranoia/pull/441) Recursive restore with has_many/one through assocs (#441)
12
22
  [Emil Ong](https://github.com/emilong)
13
23
 
14
- ## 2.6.1
24
+ ## 2.6.1 - Nov 16, 2022
15
25
 
16
26
  * [#535](https://github.com/rubysherpas/paranoia/pull/535) Allow to skip updating paranoia_destroy_attributes for records while really_destroy!
17
27
  [Anton Bogdanov](https://github.com/kortirso)
18
28
 
19
- ## 2.6.0
29
+ ## 2.6.0 - Mar 23, 2022
20
30
 
21
31
  * [#512](https://github.com/rubysherpas/paranoia/pull/512) Quote table names; Mysql 8 has keywords that might match table names which cause an exception.
22
32
  * [#476](https://github.com/rubysherpas/paranoia/pull/476) Fix syntax error in documentation.
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = '2.6.3'.freeze
2
+ VERSION = '2.6.4'.freeze
3
3
  end
data/lib/paranoia.rb CHANGED
@@ -24,6 +24,7 @@ module Paranoia
24
24
  module Query
25
25
  def paranoid? ; true ; end
26
26
 
27
+ # If you want to find all records, even those which are deleted
27
28
  def with_deleted
28
29
  if ActiveRecord::VERSION::STRING >= "4.1"
29
30
  return unscope where: paranoia_column
@@ -31,6 +32,7 @@ module Paranoia
31
32
  all.tap { |x| x.default_scoped = false }
32
33
  end
33
34
 
35
+ # If you want to find only the deleted records
34
36
  def only_deleted
35
37
  if paranoia_sentinel_value.nil?
36
38
  return with_deleted.where.not(paranoia_column => paranoia_sentinel_value)
@@ -45,6 +47,7 @@ module Paranoia
45
47
  end
46
48
  alias_method :deleted, :only_deleted
47
49
 
50
+ # If you want to restore a record
48
51
  def restore(id_or_ids, opts = {})
49
52
  ids = Array(id_or_ids).flatten
50
53
  any_object_instead_of_id = ids.any? { |id| ActiveRecord::Base === id }
@@ -173,8 +176,25 @@ module Paranoia
173
176
 
174
177
  private
175
178
 
179
+ def counter_cache_disabled?
180
+ defined?(@_disable_counter_cache) && @_disable_counter_cache
181
+ end
182
+
183
+ def counter_cached_association_names
184
+ return [] if counter_cache_disabled?
185
+ super
186
+ end
187
+
176
188
  def each_counter_cached_associations
177
- !(defined?(@_disable_counter_cache) && @_disable_counter_cache) ? super : []
189
+ return [] if counter_cache_disabled?
190
+
191
+ if defined?(super)
192
+ super
193
+ else
194
+ counter_cached_association_names.each do |name|
195
+ yield association(name)
196
+ end
197
+ end
178
198
  end
179
199
 
180
200
  def paranoia_restore_attributes
@@ -193,6 +213,16 @@ module Paranoia
193
213
  timestamp_attributes_for_update_in_model.each_with_object({}) { |attr,hash| hash[attr] = current_time_from_proper_timezone }
194
214
  end
195
215
 
216
+ def paranoia_find_has_one_target(association)
217
+ association_foreign_key = association.options[:through].present? ? association.klass.primary_key : association.foreign_key
218
+ association_find_conditions = { association_foreign_key => self.id }
219
+ association_find_conditions[association.type] = self.class.name if association.type
220
+
221
+ scope = association.klass.only_deleted.where(association_find_conditions)
222
+ scope = scope.merge(association.scope) if association.scope
223
+ scope.first
224
+ end
225
+
196
226
  # restore associated records that have been soft deleted when
197
227
  # we called #destroy
198
228
  def restore_associated_records(recovery_window_range = nil)
@@ -216,13 +246,8 @@ module Paranoia
216
246
  end
217
247
 
218
248
  if association_data.nil? && association.macro.to_s == "has_one"
219
- association_class = association.klass
220
- if association_class.paranoid?
221
- association_foreign_key = association.options[:through].present? ? association.klass.primary_key : association.foreign_key
222
- association_find_conditions = { association_foreign_key => self.id }
223
- association_find_conditions[association.type] = self.class.name if association.type
224
-
225
- association_class.only_deleted.where(association_find_conditions).first
249
+ if association.klass.paranoid?
250
+ paranoia_find_has_one_target(association)
226
251
  .try!(:restore, recursive: true, :recovery_window_range => recovery_window_range)
227
252
  end
228
253
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paranoia
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - radarlistener@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2024-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: 1.3.6
108
108
  requirements: []
109
- rubygems_version: 3.4.18
109
+ rubygems_version: 3.5.11
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5,