paranoia 2.6.2 → 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: 5435d5ed0b4879dda1edf99c6cebfa860d8ae87a7420dea64289b6f53fc48314
4
- data.tar.gz: af9635bbfa0477de0acf5cf18160b28e4f7e18ed0e41f551ae9e8a63146d3083
3
+ metadata.gz: 1c181b837c0b9148cea47aaac1d370b142037943ee9e115ca14c2c1ae794c384
4
+ data.tar.gz: 9bbd8a2b61fe1a68871f11af0673ddb9ae83ae3bb51ff887354f758d300cac11
5
5
  SHA512:
6
- metadata.gz: 1a8b413670e0cfc193cb061ff7a9f4edec3765bfde3c4e3f37e43ecc0136f7adecf6ffb0ba5ee29791949e98b4a07daa0bdc58cbcd9c0ee30e13daddd9c4a3b9
7
- data.tar.gz: 893ade53cdf583809902904061b8deae5a337042b41df30c373937b29fa310ea9945dd494b35ae566d52005f672bf1d4529d458c684a12a0226a0197898a5b2d
6
+ metadata.gz: f8824844107b4cd59840c174b99a2ce7f92ed03762ec5fffcf912f26be59a5fe52480a93b66515631b608ee6c575e664444b8b48414e3efef757ef42250adf32
7
+ data.tar.gz: cf0fc54e5a6b8906ad3cbf864c3a40250b6e7f9a2775f911e33e4ae420a5354c0ddde54936e033b9fc15be0e0dabc58b5db3a70a9b0f17b2ba610d1dfb628e5e
@@ -15,11 +15,13 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- rails: ["~> 7.0.0", "~> 6.1.0", "~> 6.0.0"]
18
+ rails: ["~> 7.1.0", "~> 7.0.0", "~> 6.1.0", "~> 6.0.0"]
19
19
  ruby: ["3.2.2", "3.1.4", "3.0.6", "2.7.8"]
20
20
  include:
21
21
  - ruby: 3.2
22
22
  rails: 'edge'
23
+ - ruby: 3.2
24
+ rails: '~> 7.1.0'
23
25
  # single test failure with jruby
24
26
  #- ruby: jruby-9.4
25
27
  # rails: '~> 7.0.0'
@@ -43,7 +45,7 @@ jobs:
43
45
  env:
44
46
  RAILS: ${{ matrix.rails }}
45
47
  steps:
46
- - uses: actions/checkout@v2
48
+ - uses: actions/checkout@v4
47
49
  - uses: ruby/setup-ruby@v1
48
50
  with:
49
51
  ruby-version: ${{ matrix.ruby }}
data/CHANGELOG.md CHANGED
@@ -1,16 +1,32 @@
1
1
  # paranoia Changelog
2
2
 
3
- ## 2.6.2
3
+ ## 2.6.4 - July 20, 2024
4
+
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)
17
+ [Indyarocks](https://github.com/indyarocks)
18
+
19
+ ## 2.6.2 - Jun 6, 2023
4
20
 
5
21
  * [#441](https://github.com/rubysherpas/paranoia/pull/441) Recursive restore with has_many/one through assocs (#441)
6
22
  [Emil Ong](https://github.com/emilong)
7
23
 
8
- ## 2.6.1
24
+ ## 2.6.1 - Nov 16, 2022
9
25
 
10
26
  * [#535](https://github.com/rubysherpas/paranoia/pull/535) Allow to skip updating paranoia_destroy_attributes for records while really_destroy!
11
27
  [Anton Bogdanov](https://github.com/kortirso)
12
28
 
13
- ## 2.6.0
29
+ ## 2.6.0 - Mar 23, 2022
14
30
 
15
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.
16
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.2'.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 }
@@ -60,7 +63,7 @@ module Paranoia
60
63
  def paranoia_destroy
61
64
  with_transaction_returning_status do
62
65
  result = run_callbacks(:destroy) do
63
- @_disable_counter_cache = deleted?
66
+ @_disable_counter_cache = paranoia_destroyed?
64
67
  result = paranoia_delete
65
68
  next result unless result && ActiveRecord::VERSION::STRING >= '4.2'
66
69
  each_counter_cached_associations do |association|
@@ -73,7 +76,7 @@ module Paranoia
73
76
  @_disable_counter_cache = false
74
77
  result
75
78
  end
76
- raise ActiveRecord::Rollback, "Not destroyed" unless self.deleted?
79
+ raise ActiveRecord::Rollback, "Not destroyed" unless paranoia_destroyed?
77
80
  result
78
81
  end || false
79
82
  end
@@ -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,24 +246,8 @@ module Paranoia
216
246
  end
217
247
 
218
248
  if association_data.nil? && association.macro.to_s == "has_one"
219
- association_class_name = association.klass.name
220
-
221
- association_foreign_key = if association.options[:through].present?
222
- association.klass.primary_key
223
- else
224
- association.foreign_key
225
- end
226
-
227
- if association.type
228
- association_polymorphic_type = association.type
229
- association_find_conditions = { association_polymorphic_type => self.class.name.to_s, association_foreign_key => self.id }
230
- else
231
- association_find_conditions = { association_foreign_key => self.id }
232
- end
233
-
234
- association_class = association.klass
235
- if association_class.paranoid?
236
- association_class.only_deleted.where(association_find_conditions).first
249
+ if association.klass.paranoid?
250
+ paranoia_find_has_one_target(association)
237
251
  .try!(:restore, recursive: true, :recovery_window_range => recovery_window_range)
238
252
  end
239
253
  end
data/paranoia.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.license = 'MIT'
12
12
  s.summary = "Paranoia is a re-implementation of acts_as_paranoid for Rails 3, 4, and 5, using much, much, much less code."
13
13
  s.description = <<-DSC
14
- Paranoia is a re-implementation of acts_as_paranoid for Rails 4, 5, 6, and 7,
14
+ Paranoia is a re-implementation of acts_as_paranoid for Rails 5, 6, and 7,
15
15
  using much, much, much less code. You would use either plugin / gem if you
16
16
  wished that when you called destroy on an Active Record object that it
17
17
  didn't actually destroy it, but just "hid" the record. Paranoia does this
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.required_ruby_version = '>= 2.5'
26
26
 
27
- s.add_dependency 'activerecord', '>= 5.1', '< 7.1'
27
+ s.add_dependency 'activerecord', '>= 5.1', '< 7.2'
28
28
 
29
29
  s.add_development_dependency "bundler", ">= 1.0.0"
30
30
  s.add_development_dependency "rake"
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.2
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-06-05 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
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '5.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  description: |2
62
- Paranoia is a re-implementation of acts_as_paranoid for Rails 4, 5, 6, and 7,
62
+ Paranoia is a re-implementation of acts_as_paranoid for Rails 5, 6, and 7,
63
63
  using much, much, much less code. You would use either plugin / gem if you
64
64
  wished that when you called destroy on an Active Record object that it
65
65
  didn't actually destroy it, but just "hid" the record. Paranoia does this
@@ -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.11
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,