guard_against_physical_delete 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +31 -0
- data/.gitignore +0 -1
- data/CHANGELOG.md +50 -0
- data/README.md +52 -0
- data/bin/setup +8 -0
- data/bin/test +8 -0
- data/gemfiles/Gemfile_rails_5.0.rb +6 -0
- data/gemfiles/Gemfile_rails_5.0.rb.lock +75 -0
- data/gemfiles/Gemfile_rails_5.1.rb +5 -0
- data/gemfiles/Gemfile_rails_5.1.rb.lock +75 -0
- data/gemfiles/Gemfile_rails_5.2.rb +5 -0
- data/gemfiles/Gemfile_rails_5.2.rb.lock +75 -0
- data/gemfiles/Gemfile_rails_6.0.rb +5 -0
- data/gemfiles/Gemfile_rails_6.0.rb.lock +75 -0
- data/gemfiles/Gemfile_rails_6.1.rb +5 -0
- data/gemfiles/Gemfile_rails_6.1.rb.lock +74 -0
- data/gemfiles/Gemfile_rails_7.0.rb +5 -0
- data/gemfiles/Gemfile_rails_7.0.rb.lock +72 -0
- data/guard_against_physical_delete.gemspec +6 -6
- data/lib/guard_against_physical_delete/base.rb +10 -11
- data/lib/guard_against_physical_delete/support_counter_cache/associations/builder/belongs_to.rb +24 -37
- data/lib/guard_against_physical_delete/version.rb +1 -1
- metadata +34 -12
- data/.travis.yml +0 -7
- data/Gemfile +0 -3
- data/README.rdoc +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 652fcb3e43a6cad863c16e98d22b99128a43e2569c003c567338ecb67d27337a
|
4
|
+
data.tar.gz: d0b3ae718f26049bf882788b064dbb3c4134a5644611ac1d8832df25f416f659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18c727e7d397efa033762a262eaa7745c16d2e7da910d545f35533c39a007f359ab3e44612e772ecc18e96b1675c011acab6a845ab7e662ff2eca09e3fca3084
|
7
|
+
data.tar.gz: ed9aa438fba468cb563a27dd3c98cb48c9b3cd0767e31182483443ecf434716eb5fc2fbcfab15ebb1c5e83475b81079d1c90642fdfcc9ec876b6fcc4ff7ee5be
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
spec:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
rails_version:
|
15
|
+
- "5.0"
|
16
|
+
- "5.1"
|
17
|
+
- "5.2"
|
18
|
+
- "6.0"
|
19
|
+
- "6.1"
|
20
|
+
- "7.0"
|
21
|
+
name: Test on Rails ${{ matrix.rails_version }}
|
22
|
+
env:
|
23
|
+
BUNDLE_GEMFILE: gemfiles/Gemfile_rails_${{ matrix.rails_version }}.rb
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: 2.7
|
29
|
+
bundler-cache: true
|
30
|
+
- name: rspec
|
31
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 2.2.0 - 2022-06-16
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Support activerecord 7.0.
|
10
|
+
|
11
|
+
## 2.1.1 - 2022-05-26
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Support activerecord 6.1.
|
16
|
+
|
17
|
+
## 2.1.0 - 2021-12-02
|
18
|
+
|
19
|
+
### Added
|
20
|
+
|
21
|
+
- Support activerecord 6.0.
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
|
25
|
+
- Fix bug that it doesn't guard `#destroy` on activerecord 5.2.
|
26
|
+
|
27
|
+
## 2.0.0 - 2021-08-04
|
28
|
+
|
29
|
+
### Added
|
30
|
+
|
31
|
+
- Support activerecord 5.
|
32
|
+
|
33
|
+
### Removed
|
34
|
+
|
35
|
+
- Drop support for ruby < 2.0.
|
36
|
+
- Drop support for activerecord < 5.
|
37
|
+
|
38
|
+
## 1.0.2 - 2017-03-16
|
39
|
+
|
40
|
+
## 1.0.1 - 2017-03-09
|
41
|
+
|
42
|
+
### Fixed
|
43
|
+
|
44
|
+
- Fix files in gemspec.
|
45
|
+
|
46
|
+
## 1.0.0 - 2017-03-09
|
47
|
+
|
48
|
+
### Added
|
49
|
+
|
50
|
+
- Initial release.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# guard_against_physical_delete
|
2
|
+
|
3
|
+
[![test](https://github.com/cookpad/guard_against_physical_delete/actions/workflows/test.yml/badge.svg)](https://github.com/cookpad/guard_against_physical_delete/actions/workflows/test.yml)
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/guard_against_physical_delete.svg)](https://rubygems.org/gems/guard_against_physical_delete)
|
6
|
+
|
7
|
+
A monkey patch for ActiveRecord to prevent physical deletion.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your Rails application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'guard_against_physical_delete'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```shell
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
If there is a record with a column named `deleted_at`,
|
26
|
+
an exception is automatically raised on the methods that are likely to perform physical deletion.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# This will raise `GuardAgainstPhysicalDelete::PhysicalDeleteError`.
|
30
|
+
user.delete
|
31
|
+
|
32
|
+
# To allow phsycal deletion, do it in `physical_delete { ... }` block.
|
33
|
+
user.class.physical_delete do
|
34
|
+
user.delete
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
### Configuration
|
39
|
+
|
40
|
+
If you want to use a column name other than `deleted_at`,
|
41
|
+
you can change it as follows:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class User < ApplicationRecord
|
45
|
+
self.logical_delete_column = :removed_at
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
This gem is available as open source under the terms of the MIT License.
|
52
|
+
See [License.txt](/License.txt) for more details.
|
data/bin/setup
ADDED
data/bin/test
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
guard_against_physical_delete (2.2.0)
|
5
|
+
activerecord (>= 5, < 7.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.0.7.2)
|
11
|
+
activesupport (= 5.0.7.2)
|
12
|
+
activerecord (5.0.7.2)
|
13
|
+
activemodel (= 5.0.7.2)
|
14
|
+
activesupport (= 5.0.7.2)
|
15
|
+
arel (~> 7.0)
|
16
|
+
activesupport (5.0.7.2)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
arel (7.1.4)
|
22
|
+
concurrent-ruby (1.1.9)
|
23
|
+
countdownlatch (1.0.0)
|
24
|
+
database_cleaner (2.0.1)
|
25
|
+
database_cleaner-active_record (~> 2.0.0)
|
26
|
+
database_cleaner-active_record (2.0.1)
|
27
|
+
activerecord (>= 5.a)
|
28
|
+
database_cleaner-core (~> 2.0.0)
|
29
|
+
database_cleaner-core (2.0.1)
|
30
|
+
diff-lcs (1.4.4)
|
31
|
+
docile (1.4.0)
|
32
|
+
i18n (1.8.11)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
minitest (5.14.4)
|
35
|
+
rake (13.0.6)
|
36
|
+
rspec (3.10.0)
|
37
|
+
rspec-core (~> 3.10.0)
|
38
|
+
rspec-expectations (~> 3.10.0)
|
39
|
+
rspec-mocks (~> 3.10.0)
|
40
|
+
rspec-core (3.10.1)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-expectations (3.10.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-mocks (3.10.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.10.0)
|
48
|
+
rspec-support (3.10.3)
|
49
|
+
simplecov (0.21.2)
|
50
|
+
docile (~> 1.1)
|
51
|
+
simplecov-html (~> 0.11)
|
52
|
+
simplecov_json_formatter (~> 0.1)
|
53
|
+
simplecov-html (0.12.3)
|
54
|
+
simplecov_json_formatter (0.1.3)
|
55
|
+
sqlite3 (1.3.13)
|
56
|
+
thread_safe (0.3.6)
|
57
|
+
tzinfo (1.2.9)
|
58
|
+
thread_safe (~> 0.1)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
x86_64-linux
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
activerecord (~> 5.0.0)
|
65
|
+
bundler
|
66
|
+
countdownlatch
|
67
|
+
database_cleaner
|
68
|
+
guard_against_physical_delete!
|
69
|
+
rake (~> 13)
|
70
|
+
rspec (~> 3)
|
71
|
+
simplecov
|
72
|
+
sqlite3 (~> 1.3.0)
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.2.29
|
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
guard_against_physical_delete (2.2.0)
|
5
|
+
activerecord (>= 5, < 7.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.1.7)
|
11
|
+
activesupport (= 5.1.7)
|
12
|
+
activerecord (5.1.7)
|
13
|
+
activemodel (= 5.1.7)
|
14
|
+
activesupport (= 5.1.7)
|
15
|
+
arel (~> 8.0)
|
16
|
+
activesupport (5.1.7)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
arel (8.0.0)
|
22
|
+
concurrent-ruby (1.1.9)
|
23
|
+
countdownlatch (1.0.0)
|
24
|
+
database_cleaner (2.0.1)
|
25
|
+
database_cleaner-active_record (~> 2.0.0)
|
26
|
+
database_cleaner-active_record (2.0.1)
|
27
|
+
activerecord (>= 5.a)
|
28
|
+
database_cleaner-core (~> 2.0.0)
|
29
|
+
database_cleaner-core (2.0.1)
|
30
|
+
diff-lcs (1.4.4)
|
31
|
+
docile (1.4.0)
|
32
|
+
i18n (1.8.11)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
minitest (5.14.4)
|
35
|
+
rake (13.0.6)
|
36
|
+
rspec (3.10.0)
|
37
|
+
rspec-core (~> 3.10.0)
|
38
|
+
rspec-expectations (~> 3.10.0)
|
39
|
+
rspec-mocks (~> 3.10.0)
|
40
|
+
rspec-core (3.10.1)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-expectations (3.10.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-mocks (3.10.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.10.0)
|
48
|
+
rspec-support (3.10.3)
|
49
|
+
simplecov (0.21.2)
|
50
|
+
docile (~> 1.1)
|
51
|
+
simplecov-html (~> 0.11)
|
52
|
+
simplecov_json_formatter (~> 0.1)
|
53
|
+
simplecov-html (0.12.3)
|
54
|
+
simplecov_json_formatter (0.1.3)
|
55
|
+
sqlite3 (1.4.2)
|
56
|
+
thread_safe (0.3.6)
|
57
|
+
tzinfo (1.2.9)
|
58
|
+
thread_safe (~> 0.1)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
x86_64-linux
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
activerecord (~> 5.1.0)
|
65
|
+
bundler
|
66
|
+
countdownlatch
|
67
|
+
database_cleaner
|
68
|
+
guard_against_physical_delete!
|
69
|
+
rake (~> 13)
|
70
|
+
rspec (~> 3)
|
71
|
+
simplecov
|
72
|
+
sqlite3 (~> 1.4)
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.2.29
|
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
guard_against_physical_delete (2.2.0)
|
5
|
+
activerecord (>= 5, < 7.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.2.6)
|
11
|
+
activesupport (= 5.2.6)
|
12
|
+
activerecord (5.2.6)
|
13
|
+
activemodel (= 5.2.6)
|
14
|
+
activesupport (= 5.2.6)
|
15
|
+
arel (>= 9.0)
|
16
|
+
activesupport (5.2.6)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 0.7, < 2)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
arel (9.0.0)
|
22
|
+
concurrent-ruby (1.1.9)
|
23
|
+
countdownlatch (1.0.0)
|
24
|
+
database_cleaner (2.0.1)
|
25
|
+
database_cleaner-active_record (~> 2.0.0)
|
26
|
+
database_cleaner-active_record (2.0.1)
|
27
|
+
activerecord (>= 5.a)
|
28
|
+
database_cleaner-core (~> 2.0.0)
|
29
|
+
database_cleaner-core (2.0.1)
|
30
|
+
diff-lcs (1.4.4)
|
31
|
+
docile (1.4.0)
|
32
|
+
i18n (1.8.11)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
minitest (5.14.4)
|
35
|
+
rake (13.0.6)
|
36
|
+
rspec (3.10.0)
|
37
|
+
rspec-core (~> 3.10.0)
|
38
|
+
rspec-expectations (~> 3.10.0)
|
39
|
+
rspec-mocks (~> 3.10.0)
|
40
|
+
rspec-core (3.10.1)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-expectations (3.10.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-mocks (3.10.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.10.0)
|
48
|
+
rspec-support (3.10.3)
|
49
|
+
simplecov (0.21.2)
|
50
|
+
docile (~> 1.1)
|
51
|
+
simplecov-html (~> 0.11)
|
52
|
+
simplecov_json_formatter (~> 0.1)
|
53
|
+
simplecov-html (0.12.3)
|
54
|
+
simplecov_json_formatter (0.1.3)
|
55
|
+
sqlite3 (1.4.2)
|
56
|
+
thread_safe (0.3.6)
|
57
|
+
tzinfo (1.2.9)
|
58
|
+
thread_safe (~> 0.1)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
x86_64-linux
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
activerecord (~> 5.2.0)
|
65
|
+
bundler
|
66
|
+
countdownlatch
|
67
|
+
database_cleaner
|
68
|
+
guard_against_physical_delete!
|
69
|
+
rake (~> 13)
|
70
|
+
rspec (~> 3)
|
71
|
+
simplecov
|
72
|
+
sqlite3 (~> 1.4)
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.2.29
|
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
guard_against_physical_delete (2.2.0)
|
5
|
+
activerecord (>= 5, < 7.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.0.4.1)
|
11
|
+
activesupport (= 6.0.4.1)
|
12
|
+
activerecord (6.0.4.1)
|
13
|
+
activemodel (= 6.0.4.1)
|
14
|
+
activesupport (= 6.0.4.1)
|
15
|
+
activesupport (6.0.4.1)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 0.7, < 2)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
tzinfo (~> 1.1)
|
20
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
21
|
+
concurrent-ruby (1.1.9)
|
22
|
+
countdownlatch (1.0.0)
|
23
|
+
database_cleaner (2.0.1)
|
24
|
+
database_cleaner-active_record (~> 2.0.0)
|
25
|
+
database_cleaner-active_record (2.0.1)
|
26
|
+
activerecord (>= 5.a)
|
27
|
+
database_cleaner-core (~> 2.0.0)
|
28
|
+
database_cleaner-core (2.0.1)
|
29
|
+
diff-lcs (1.4.4)
|
30
|
+
docile (1.4.0)
|
31
|
+
i18n (1.8.11)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
minitest (5.14.4)
|
34
|
+
rake (13.0.6)
|
35
|
+
rspec (3.10.0)
|
36
|
+
rspec-core (~> 3.10.0)
|
37
|
+
rspec-expectations (~> 3.10.0)
|
38
|
+
rspec-mocks (~> 3.10.0)
|
39
|
+
rspec-core (3.10.1)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-expectations (3.10.1)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-mocks (3.10.2)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-support (3.10.3)
|
48
|
+
simplecov (0.21.2)
|
49
|
+
docile (~> 1.1)
|
50
|
+
simplecov-html (~> 0.11)
|
51
|
+
simplecov_json_formatter (~> 0.1)
|
52
|
+
simplecov-html (0.12.3)
|
53
|
+
simplecov_json_formatter (0.1.3)
|
54
|
+
sqlite3 (1.4.2)
|
55
|
+
thread_safe (0.3.6)
|
56
|
+
tzinfo (1.2.9)
|
57
|
+
thread_safe (~> 0.1)
|
58
|
+
zeitwerk (2.5.1)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
x86_64-linux
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
activerecord (~> 6.0.0)
|
65
|
+
bundler
|
66
|
+
countdownlatch
|
67
|
+
database_cleaner
|
68
|
+
guard_against_physical_delete!
|
69
|
+
rake (~> 13)
|
70
|
+
rspec (~> 3)
|
71
|
+
simplecov
|
72
|
+
sqlite3 (~> 1.4)
|
73
|
+
|
74
|
+
BUNDLED WITH
|
75
|
+
2.2.29
|
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
guard_against_physical_delete (2.2.0)
|
5
|
+
activerecord (>= 5, < 7.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (6.1.4.1)
|
11
|
+
activesupport (= 6.1.4.1)
|
12
|
+
activerecord (6.1.4.1)
|
13
|
+
activemodel (= 6.1.4.1)
|
14
|
+
activesupport (= 6.1.4.1)
|
15
|
+
activesupport (6.1.4.1)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
zeitwerk (~> 2.3)
|
21
|
+
concurrent-ruby (1.1.9)
|
22
|
+
countdownlatch (1.0.0)
|
23
|
+
database_cleaner (2.0.1)
|
24
|
+
database_cleaner-active_record (~> 2.0.0)
|
25
|
+
database_cleaner-active_record (2.0.1)
|
26
|
+
activerecord (>= 5.a)
|
27
|
+
database_cleaner-core (~> 2.0.0)
|
28
|
+
database_cleaner-core (2.0.1)
|
29
|
+
diff-lcs (1.4.4)
|
30
|
+
docile (1.4.0)
|
31
|
+
i18n (1.8.11)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
minitest (5.14.4)
|
34
|
+
rake (13.0.6)
|
35
|
+
rspec (3.10.0)
|
36
|
+
rspec-core (~> 3.10.0)
|
37
|
+
rspec-expectations (~> 3.10.0)
|
38
|
+
rspec-mocks (~> 3.10.0)
|
39
|
+
rspec-core (3.10.1)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-expectations (3.10.1)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-mocks (3.10.2)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-support (3.10.3)
|
48
|
+
simplecov (0.21.2)
|
49
|
+
docile (~> 1.1)
|
50
|
+
simplecov-html (~> 0.11)
|
51
|
+
simplecov_json_formatter (~> 0.1)
|
52
|
+
simplecov-html (0.12.3)
|
53
|
+
simplecov_json_formatter (0.1.3)
|
54
|
+
sqlite3 (1.4.2)
|
55
|
+
tzinfo (2.0.4)
|
56
|
+
concurrent-ruby (~> 1.0)
|
57
|
+
zeitwerk (2.5.1)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
x86_64-linux
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
activerecord (~> 6.1.0)
|
64
|
+
bundler
|
65
|
+
countdownlatch
|
66
|
+
database_cleaner
|
67
|
+
guard_against_physical_delete!
|
68
|
+
rake (~> 13)
|
69
|
+
rspec (~> 3)
|
70
|
+
simplecov
|
71
|
+
sqlite3 (~> 1.4)
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.2.29
|
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
guard_against_physical_delete (2.2.0)
|
5
|
+
activerecord (>= 5, < 7.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (7.0.2.2)
|
11
|
+
activesupport (= 7.0.2.2)
|
12
|
+
activerecord (7.0.2.2)
|
13
|
+
activemodel (= 7.0.2.2)
|
14
|
+
activesupport (= 7.0.2.2)
|
15
|
+
activesupport (7.0.2.2)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
concurrent-ruby (1.1.9)
|
21
|
+
countdownlatch (1.0.0)
|
22
|
+
database_cleaner (2.0.1)
|
23
|
+
database_cleaner-active_record (~> 2.0.0)
|
24
|
+
database_cleaner-active_record (2.0.1)
|
25
|
+
activerecord (>= 5.a)
|
26
|
+
database_cleaner-core (~> 2.0.0)
|
27
|
+
database_cleaner-core (2.0.1)
|
28
|
+
diff-lcs (1.5.0)
|
29
|
+
docile (1.4.0)
|
30
|
+
i18n (1.10.0)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
minitest (5.15.0)
|
33
|
+
rake (13.0.6)
|
34
|
+
rspec (3.11.0)
|
35
|
+
rspec-core (~> 3.11.0)
|
36
|
+
rspec-expectations (~> 3.11.0)
|
37
|
+
rspec-mocks (~> 3.11.0)
|
38
|
+
rspec-core (3.11.0)
|
39
|
+
rspec-support (~> 3.11.0)
|
40
|
+
rspec-expectations (3.11.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.11.0)
|
43
|
+
rspec-mocks (3.11.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.11.0)
|
46
|
+
rspec-support (3.11.0)
|
47
|
+
simplecov (0.21.2)
|
48
|
+
docile (~> 1.1)
|
49
|
+
simplecov-html (~> 0.11)
|
50
|
+
simplecov_json_formatter (~> 0.1)
|
51
|
+
simplecov-html (0.12.3)
|
52
|
+
simplecov_json_formatter (0.1.4)
|
53
|
+
sqlite3 (1.4.2)
|
54
|
+
tzinfo (2.0.4)
|
55
|
+
concurrent-ruby (~> 1.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
x86_64-linux
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
activerecord (~> 7.0.0)
|
62
|
+
bundler
|
63
|
+
countdownlatch
|
64
|
+
database_cleaner
|
65
|
+
guard_against_physical_delete!
|
66
|
+
rake (~> 13)
|
67
|
+
rspec (~> 3)
|
68
|
+
simplecov
|
69
|
+
sqlite3 (~> 1.4)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.3.6
|
@@ -9,18 +9,18 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
10
|
s.authors = ["MORITA shingo"]
|
11
11
|
s.date = "2012-03-06"
|
12
|
-
s.description = "Guard against physical delete"
|
13
12
|
s.email = "morita@cookpad.com"
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"README.rdoc"
|
16
|
-
]
|
17
13
|
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
18
14
|
s.homepage = "http://github.com/cookpad/guard_against_physical_delete"
|
19
15
|
s.require_paths = ["lib"]
|
20
16
|
s.rubygems_version = "1.8.15"
|
21
|
-
s.summary = "
|
17
|
+
s.summary = "A monkey patch for ActiveRecord to prevent physical deletion."
|
22
18
|
|
23
|
-
s.
|
19
|
+
s.metadata["changelog_uri"] = "#{s.homepage}/blob/master/CHANGELOG.md"
|
20
|
+
s.metadata["homepage_uri"] = s.homepage
|
21
|
+
s.metadata["source_code_uri"] = s.homepage
|
22
|
+
|
23
|
+
s.add_runtime_dependency "activerecord", ">= 5", "< 7.1"
|
24
24
|
s.add_development_dependency "rake", "~> 13"
|
25
25
|
s.add_development_dependency "rspec", "~> 3"
|
26
26
|
s.add_development_dependency "sqlite3", "~> 1.4"
|
@@ -12,7 +12,6 @@ module GuardAgainstPhysicalDelete
|
|
12
12
|
set_logical_delete_column :deleted_at
|
13
13
|
end
|
14
14
|
obj.send(:include, InstanceMethods)
|
15
|
-
obj.prepend MethodOverrides if ActiveRecord.version >= Gem::Version.new('5.2.0') # #delete no longer calls Relation#delete_all
|
16
15
|
end
|
17
16
|
|
18
17
|
module ClassMethods
|
@@ -45,6 +44,16 @@ module GuardAgainstPhysicalDelete
|
|
45
44
|
end
|
46
45
|
|
47
46
|
module InstanceMethods
|
47
|
+
if ::ActiveRecord.version >= ::Gem::Version.new('5.2')
|
48
|
+
def _delete_row
|
49
|
+
unless self.class.delete_permitted?
|
50
|
+
raise ::GuardAgainstPhysicalDelete::PhysicalDeleteError, self.class.name
|
51
|
+
end
|
52
|
+
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
48
57
|
def hard_delete
|
49
58
|
self.class.physical_delete { destroy }
|
50
59
|
end
|
@@ -54,15 +63,5 @@ module GuardAgainstPhysicalDelete
|
|
54
63
|
self.save!
|
55
64
|
end
|
56
65
|
end
|
57
|
-
|
58
|
-
module MethodOverrides
|
59
|
-
def delete
|
60
|
-
unless self.class.delete_permitted?
|
61
|
-
raise GuardAgainstPhysicalDelete::PhysicalDeleteError, self.class.name
|
62
|
-
end
|
63
|
-
|
64
|
-
super
|
65
|
-
end
|
66
|
-
end
|
67
66
|
end
|
68
67
|
end
|
data/lib/guard_against_physical_delete/support_counter_cache/associations/builder/belongs_to.rb
CHANGED
@@ -11,41 +11,32 @@ module GuardAgainstPhysicalDelete
|
|
11
11
|
|
12
12
|
def add_logical_delete_counter_cache_methods(mixin)
|
13
13
|
mixin.class_eval do
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
delete_column = self.logical_delete_column
|
27
|
-
return unless saved_change_to_logical_delete_column?(delete_column)
|
28
|
-
return if logical_delete_column_before_last_save(delete_column).nil?
|
29
|
-
return unless send(delete_column).nil?
|
30
|
-
record = send(reflection.name)
|
31
|
-
record.class.increment_counter(cache_column, record.id) unless record.nil?
|
14
|
+
def adjust_counter_caches_for_logical_deletion(reflection)
|
15
|
+
if attribute_before_last_save(logical_delete_column).nil? && read_attribute(logical_delete_column)
|
16
|
+
reflection.klass.decrement_counter(
|
17
|
+
reflection.counter_cache_column,
|
18
|
+
attribute_before_last_save(reflection.foreign_key)
|
19
|
+
)
|
20
|
+
elsif attribute_before_last_save(logical_delete_column) && read_attribute(logical_delete_column).nil?
|
21
|
+
reflection.klass.increment_counter(
|
22
|
+
reflection.counter_cache_column,
|
23
|
+
attribute_before_last_save(reflection.foreign_key)
|
24
|
+
)
|
25
|
+
end
|
32
26
|
end
|
33
27
|
|
28
|
+
# Polyfill for Rails < 5.1, not that it's perfectly compatible.
|
34
29
|
if ActiveRecord.version < Gem::Version.new('5.1.0')
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def logical_delete_column_before_last_save(delete_column)
|
40
|
-
__send__("#{delete_column}_was")
|
41
|
-
end
|
42
|
-
else
|
43
|
-
def saved_change_to_logical_delete_column?(delete_column)
|
44
|
-
__send__("saved_change_to_#{delete_column}?")
|
30
|
+
# @param [#to_s] attr_name
|
31
|
+
# @return [Object]
|
32
|
+
def attribute_before_last_save(attr_name)
|
33
|
+
__send__("#{attr_name}_was")
|
45
34
|
end
|
46
35
|
|
47
|
-
|
48
|
-
|
36
|
+
# @param [#to_s] attr_name
|
37
|
+
# @return [Boolean]
|
38
|
+
def saved_change_to_attribute?(attr_name)
|
39
|
+
__send__("#{attr_name}_changed?")
|
49
40
|
end
|
50
41
|
end
|
51
42
|
end
|
@@ -61,19 +52,15 @@ module GuardAgainstPhysicalDelete
|
|
61
52
|
module MethodOverrides
|
62
53
|
private
|
63
54
|
|
64
|
-
def add_counter_cache_methods(mixin)
|
65
|
-
super(mixin)
|
66
|
-
add_logical_delete_counter_cache_methods(mixin)
|
67
|
-
end
|
68
|
-
|
69
55
|
def add_counter_cache_callbacks(model, reflection)
|
70
56
|
super(model, reflection)
|
71
57
|
|
72
58
|
return unless model.logical_delete?
|
73
59
|
|
60
|
+
add_logical_delete_counter_cache_methods(model)
|
61
|
+
|
74
62
|
model.after_update -> record do
|
75
|
-
record.
|
76
|
-
record.belongs_to_counter_cache_after_revive(reflection)
|
63
|
+
record.adjust_counter_caches_for_logical_deletion(reflection)
|
77
64
|
end
|
78
65
|
end
|
79
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard_against_physical_delete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MORITA shingo
|
@@ -14,16 +14,22 @@ dependencies:
|
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '5'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,19 +128,32 @@ dependencies:
|
|
122
128
|
- - ">="
|
123
129
|
- !ruby/object:Gem::Version
|
124
130
|
version: '0'
|
125
|
-
description:
|
131
|
+
description:
|
126
132
|
email: morita@cookpad.com
|
127
133
|
executables: []
|
128
134
|
extensions: []
|
129
|
-
extra_rdoc_files:
|
130
|
-
- README.rdoc
|
135
|
+
extra_rdoc_files: []
|
131
136
|
files:
|
137
|
+
- ".github/workflows/test.yml"
|
132
138
|
- ".gitignore"
|
133
|
-
-
|
134
|
-
- Gemfile
|
139
|
+
- CHANGELOG.md
|
135
140
|
- License.txt
|
136
|
-
- README.
|
141
|
+
- README.md
|
137
142
|
- Rakefile
|
143
|
+
- bin/setup
|
144
|
+
- bin/test
|
145
|
+
- gemfiles/Gemfile_rails_5.0.rb
|
146
|
+
- gemfiles/Gemfile_rails_5.0.rb.lock
|
147
|
+
- gemfiles/Gemfile_rails_5.1.rb
|
148
|
+
- gemfiles/Gemfile_rails_5.1.rb.lock
|
149
|
+
- gemfiles/Gemfile_rails_5.2.rb
|
150
|
+
- gemfiles/Gemfile_rails_5.2.rb.lock
|
151
|
+
- gemfiles/Gemfile_rails_6.0.rb
|
152
|
+
- gemfiles/Gemfile_rails_6.0.rb.lock
|
153
|
+
- gemfiles/Gemfile_rails_6.1.rb
|
154
|
+
- gemfiles/Gemfile_rails_6.1.rb.lock
|
155
|
+
- gemfiles/Gemfile_rails_7.0.rb
|
156
|
+
- gemfiles/Gemfile_rails_7.0.rb.lock
|
138
157
|
- guard_against_physical_delete.gemspec
|
139
158
|
- lib/guard_against_physical_delete.rb
|
140
159
|
- lib/guard_against_physical_delete/base.rb
|
@@ -145,7 +164,10 @@ files:
|
|
145
164
|
- lib/guard_against_physical_delete/version.rb
|
146
165
|
homepage: http://github.com/cookpad/guard_against_physical_delete
|
147
166
|
licenses: []
|
148
|
-
metadata:
|
167
|
+
metadata:
|
168
|
+
changelog_uri: http://github.com/cookpad/guard_against_physical_delete/blob/master/CHANGELOG.md
|
169
|
+
homepage_uri: http://github.com/cookpad/guard_against_physical_delete
|
170
|
+
source_code_uri: http://github.com/cookpad/guard_against_physical_delete
|
149
171
|
post_install_message:
|
150
172
|
rdoc_options: []
|
151
173
|
require_paths:
|
@@ -161,8 +183,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
183
|
- !ruby/object:Gem::Version
|
162
184
|
version: '0'
|
163
185
|
requirements: []
|
164
|
-
rubygems_version: 3.1
|
186
|
+
rubygems_version: 3.0.3.1
|
165
187
|
signing_key:
|
166
188
|
specification_version: 4
|
167
|
-
summary:
|
189
|
+
summary: A monkey patch for ActiveRecord to prevent physical deletion.
|
168
190
|
test_files: []
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/README.rdoc
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
= guard_against_physical_delete
|
2
|
-
|
3
|
-
guard_against_physical_delete is monkey patch for ActiveRecord.
|
4
|
-
This patch prevent deleting record physically.
|
5
|
-
set logical delete column name. (default is :deleted_at)
|
6
|
-
Logical.logical_delete_column = :removed_at
|
7
|
-
Logical.first.delete #=> raise GuardAgainstPhysicalDelete::PhysicalDeleteError
|
8
|
-
Logical.physical_delete { Logical.first.delete } #=> allow physical_delete
|
9
|
-
|
10
|
-
== Support
|
11
|
-
active_record >= 5.0.0, < 6.0.0
|
12
|
-
|
13
|
-
== Copyright
|
14
|
-
|
15
|
-
Copyright (c) 2012 morita shingo. See License.txt for
|
16
|
-
further details.
|
17
|
-
|