paranoia 2.6.0 → 2.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad52996a9a12b6605d8179ad1ae5ef39cb7655d19d037884518800a02f6ff160
4
- data.tar.gz: 3c9d2c4203e203b64bf0e24db1995ddfc431c8ed742ad96319f19eea2a62bc8a
3
+ metadata.gz: 1c181b837c0b9148cea47aaac1d370b142037943ee9e115ca14c2c1ae794c384
4
+ data.tar.gz: 9bbd8a2b61fe1a68871f11af0673ddb9ae83ae3bb51ff887354f758d300cac11
5
5
  SHA512:
6
- metadata.gz: ed7a78d7135fce0a513e0f5fb4c6c685c99ad788efa57e15dd9ae011d1dfce0d98bc41fd49b7688f3d706e6101b78824ada19ce3617359a085186e76acc0a2db
7
- data.tar.gz: 2a24bfb1f5d1f9b8c5e588c86bf745ed80125167dfefc6ad5a10cc3b7a66da3ee50f85b7727cda74a5f92a9a1d1b3fac0defc4296b71b1dd7f8c9e9d8496831f
6
+ metadata.gz: f8824844107b4cd59840c174b99a2ce7f92ed03762ec5fffcf912f26be59a5fe52480a93b66515631b608ee6c575e664444b8b48414e3efef757ef42250adf32
7
+ data.tar.gz: cf0fc54e5a6b8906ad3cbf864c3a40250b6e7f9a2775f911e33e4ae420a5354c0ddde54936e033b9fc15be0e0dabc58b5db3a70a9b0f17b2ba610d1dfb628e5e
@@ -15,45 +15,37 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- ruby:
19
- - 3.1
20
- - '3.0'
21
- - 2.7
22
- - 2.6
23
- - 2.5
24
- # - jruby-9.2.19.0
25
- # - jruby-9.3.1.0
26
- rails:
27
- - '~> 5.1.0'
28
- - '~> 5.2.0'
29
- - '~> 6.0.0'
30
- - '~> 6.1.0'
31
- - '~> 7.0.0'
32
- - 'edge'
33
- exclude:
34
- # Rails edge is now 7.x and requires ruby 2.7
35
- - rails: 'edge'
36
- ruby: 2.6
37
- - rails: 'edge'
38
- ruby: 2.5
39
- - rails: '~> 7.0.0'
40
- ruby: 2.6
41
- - rails: '~> 7.0.0'
42
- ruby: 2.5
43
- # Legacy Rails with newer rubies
44
- - rails: '~> 5.1.0'
45
- ruby: '3.0'
46
- - rails: '~> 5.2.0'
47
- ruby: '3.0'
48
- - rails: '~> 5.1.0'
49
- ruby: 3.1
50
- - rails: '~> 5.2.0'
51
- ruby: 3.1
18
+ rails: ["~> 7.1.0", "~> 7.0.0", "~> 6.1.0", "~> 6.0.0"]
19
+ ruby: ["3.2.2", "3.1.4", "3.0.6", "2.7.8"]
20
+ include:
21
+ - ruby: 3.2
22
+ rails: 'edge'
23
+ - ruby: 3.2
24
+ rails: '~> 7.1.0'
25
+ # single test failure with jruby
26
+ #- ruby: jruby-9.4
27
+ # rails: '~> 7.0.0'
28
+ - ruby: 2.6
29
+ rails: '~> 6.1.0'
30
+ - ruby: 2.6
31
+ rails: '~> 6.0.0'
32
+ - ruby: 2.6
33
+ rails: '~> 5.2.0'
34
+ - ruby: 2.6
35
+ rails: '~> 5.1.0'
36
+ - ruby: 2.5
37
+ rails: '~> 6.0.0'
38
+ - ruby: 2.5
39
+ rails: '~> 5.2.0'
40
+ - ruby: 2.5
41
+ rails: '~> 5.1.0'
42
+ #os: ubuntu-latest
43
+ #arch: x64
52
44
 
53
45
  env:
54
46
  RAILS: ${{ matrix.rails }}
55
47
  steps:
56
- - uses: actions/checkout@v2
48
+ - uses: actions/checkout@v4
57
49
  - uses: ruby/setup-ruby@v1
58
50
  with:
59
51
  ruby-version: ${{ matrix.ruby }}
data/CHANGELOG.md CHANGED
@@ -1,6 +1,32 @@
1
1
  # paranoia Changelog
2
2
 
3
- ## 2.6.0
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
20
+
21
+ * [#441](https://github.com/rubysherpas/paranoia/pull/441) Recursive restore with has_many/one through assocs (#441)
22
+ [Emil Ong](https://github.com/emilong)
23
+
24
+ ## 2.6.1 - Nov 16, 2022
25
+
26
+ * [#535](https://github.com/rubysherpas/paranoia/pull/535) Allow to skip updating paranoia_destroy_attributes for records while really_destroy!
27
+ [Anton Bogdanov](https://github.com/kortirso)
28
+
29
+ ## 2.6.0 - Mar 23, 2022
4
30
 
5
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.
6
32
  * [#476](https://github.com/rubysherpas/paranoia/pull/476) Fix syntax error in documentation.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/paranoia.svg)](https://badge.fury.io/rb/paranoia)
2
2
  [![build](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml/badge.svg)](https://github.com/rubysherpas/paranoia/actions/workflows/build.yml)
3
3
 
4
- **Notice:**
4
+ **Notice:**
5
5
 
6
6
  `paranoia` has some surprising behaviour (like overriding ActiveRecord's `delete` and `destroy`) and is not recommended for new projects. See [`discard`'s README](https://github.com/jhawthorn/discard#why-not-paranoia-or-acts_as_paranoid) for more details.
7
7
 
@@ -103,6 +103,14 @@ If you really want it gone *gone*, call `really_destroy!`:
103
103
  # => client
104
104
  ```
105
105
 
106
+ If you need skip updating timestamps for deleting records, call `really_destroy!(update_destroy_attributes: false)`.
107
+ When we call `really_destroy!(update_destroy_attributes: false)` on the parent `client`, then each child `email` will also have `really_destroy!(update_destroy_attributes: false)` called.
108
+
109
+ ``` ruby
110
+ >> client.really_destroy!(update_destroy_attributes: false)
111
+ # => client
112
+ ```
113
+
106
114
  If you want to use a column other than `deleted_at`, you can pass it as an option:
107
115
 
108
116
  ``` ruby
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = '2.6.0'.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
@@ -144,7 +147,7 @@ module Paranoia
144
147
  end
145
148
  alias :deleted? :paranoia_destroyed?
146
149
 
147
- def really_destroy!
150
+ def really_destroy!(update_destroy_attributes: true)
148
151
  with_transaction_returning_status do
149
152
  run_callbacks(:real_destroy) do
150
153
  @_disable_counter_cache = paranoia_destroyed?
@@ -158,12 +161,14 @@ module Paranoia
158
161
  # .paranoid? will work for both instances and classes
159
162
  next unless association_data && association_data.paranoid?
160
163
  if reflection.collection?
161
- next association_data.with_deleted.each(&:really_destroy!)
164
+ next association_data.with_deleted.find_each { |record|
165
+ record.really_destroy!(update_destroy_attributes: update_destroy_attributes)
166
+ }
162
167
  end
163
- association_data.really_destroy!
168
+ association_data.really_destroy!(update_destroy_attributes: update_destroy_attributes)
164
169
  end
165
170
  end
166
- update_columns(paranoia_destroy_attributes)
171
+ update_columns(paranoia_destroy_attributes) if update_destroy_attributes
167
172
  destroy_without_paranoia
168
173
  end
169
174
  end
@@ -171,8 +176,25 @@ module Paranoia
171
176
 
172
177
  private
173
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
+
174
188
  def each_counter_cached_associations
175
- !(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
176
198
  end
177
199
 
178
200
  def paranoia_restore_attributes
@@ -191,6 +213,16 @@ module Paranoia
191
213
  timestamp_attributes_for_update_in_model.each_with_object({}) { |attr,hash| hash[attr] = current_time_from_proper_timezone }
192
214
  end
193
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
+
194
226
  # restore associated records that have been soft deleted when
195
227
  # we called #destroy
196
228
  def restore_associated_records(recovery_window_range = nil)
@@ -214,19 +246,8 @@ module Paranoia
214
246
  end
215
247
 
216
248
  if association_data.nil? && association.macro.to_s == "has_one"
217
- association_class_name = association.klass.name
218
- association_foreign_key = association.foreign_key
219
-
220
- if association.type
221
- association_polymorphic_type = association.type
222
- association_find_conditions = { association_polymorphic_type => self.class.name.to_s, association_foreign_key => self.id }
223
- else
224
- association_find_conditions = { association_foreign_key => self.id }
225
- end
226
-
227
- association_class = association_class_name.constantize
228
- if association_class.paranoid?
229
- association_class.only_deleted.where(association_find_conditions).first
249
+ if association.klass.paranoid?
250
+ paranoia_find_has_one_target(association)
230
251
  .try!(:restore, recursive: true, :recovery_window_range => recovery_window_range)
231
252
  end
232
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.0
4
+ version: 2.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - radarlistener@gmail.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-23 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
@@ -91,7 +91,7 @@ homepage: https://github.com/rubysherpas/paranoia
91
91
  licenses:
92
92
  - MIT
93
93
  metadata: {}
94
- post_install_message:
94
+ post_install_message:
95
95
  rdoc_options: []
96
96
  require_paths:
97
97
  - lib
@@ -106,8 +106,8 @@ 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.1.6
110
- signing_key:
109
+ rubygems_version: 3.5.11
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,
113
113
  using much, much, much less code.