guard_against_physical_delete 2.0.0 → 2.1.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/master_and_pr.yml +29 -0
- data/.gitignore +0 -1
- data/CHANGELOG.md +38 -0
- data/README.md +50 -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/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 +30 -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: a37d0705c44bfcae06881a4815abb159ea31d8fd65bb805a4f511c694f2351ea
|
4
|
+
data.tar.gz: 143cf811443a35dce054b0db4751f51760d2ac8e15c738f38db11ac97b84214a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d756fd2d6058aa130b962992040fc2a473f783c7b5baacf6d249098ac3d6f736e551f6b12dd1e461c4fb4c7e38d0fd8c0f8681f3ee183618417b37ec1c311409
|
7
|
+
data.tar.gz: bd36f76383558f97b380177ab91c8daaf4d751387e4f2f1bd9753a3f198a9514d38b5d344bf3b257eab48a31b5e3e17fa70efbe2307a6f211a654101d163a621
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: master & PR
|
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
|
+
name: Test on Rails ${{ matrix.rails_version }}
|
20
|
+
env:
|
21
|
+
BUNDLE_GEMFILE: gemfiles/Gemfile_rails_${{ matrix.rails_version }}.rb
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: 2.7
|
27
|
+
bundler-cache: true
|
28
|
+
- name: rspec
|
29
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 2.1.0 - 2021-12-02
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Support activerecord 6.0.
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- Fix bug that it doesn't guard `#destroy` on activerecord 5.2.
|
14
|
+
|
15
|
+
## 2.0.0 - 2021-08-04
|
16
|
+
|
17
|
+
### Added
|
18
|
+
|
19
|
+
- Support activerecord 5.
|
20
|
+
|
21
|
+
### Removed
|
22
|
+
|
23
|
+
- Drop support for ruby < 2.0.
|
24
|
+
- Drop support for activerecord < 5.
|
25
|
+
|
26
|
+
## 1.0.2 - 2017-03-16
|
27
|
+
|
28
|
+
## 1.0.1 - 2017-03-09
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
|
32
|
+
- Fix files in gemspec.
|
33
|
+
|
34
|
+
## 1.0.0 - 2017-03-09
|
35
|
+
|
36
|
+
### Added
|
37
|
+
|
38
|
+
- Initial release.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# guard_against_physical_delete
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/guard_against_physical_delete.svg)](https://rubygems.org/gems/guard_against_physical_delete)
|
4
|
+
|
5
|
+
A monkey patch for ActiveRecord to prevent physical deletion.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your Rails application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'guard_against_physical_delete'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
If there is a record with a column named `deleted_at`,
|
24
|
+
an exception is automatically raised on the methods that are likely to perform physical deletion.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# This will raise `GuardAgainstPhysicalDelete::PhysicalDeleteError`.
|
28
|
+
user.delete
|
29
|
+
|
30
|
+
# To allow phsycal deletion, do it in `physical_delete { ... }` block.
|
31
|
+
user.class.physical_delete do
|
32
|
+
user.delete
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
### Configuration
|
37
|
+
|
38
|
+
If you want to use a column name other than `deleted_at`,
|
39
|
+
you can change it as follows:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class User < ApplicationRecord
|
43
|
+
self.logical_delete_column = :removed_at
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
This gem is available as open source under the terms of the MIT License.
|
50
|
+
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.0.0)
|
5
|
+
activerecord (>= 5, < 6.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.0.0)
|
5
|
+
activerecord (>= 5, < 6.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.0.0)
|
5
|
+
activerecord (>= 5, < 6.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.0.0)
|
5
|
+
activerecord (>= 5, < 6.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
|
@@ -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", "< 6.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? && 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) && 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.1.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: '6.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: '6.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,19 +128,28 @@ 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/master_and_pr.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
|
138
153
|
- guard_against_physical_delete.gemspec
|
139
154
|
- lib/guard_against_physical_delete.rb
|
140
155
|
- lib/guard_against_physical_delete/base.rb
|
@@ -145,7 +160,10 @@ files:
|
|
145
160
|
- lib/guard_against_physical_delete/version.rb
|
146
161
|
homepage: http://github.com/cookpad/guard_against_physical_delete
|
147
162
|
licenses: []
|
148
|
-
metadata:
|
163
|
+
metadata:
|
164
|
+
changelog_uri: http://github.com/cookpad/guard_against_physical_delete/blob/master/CHANGELOG.md
|
165
|
+
homepage_uri: http://github.com/cookpad/guard_against_physical_delete
|
166
|
+
source_code_uri: http://github.com/cookpad/guard_against_physical_delete
|
149
167
|
post_install_message:
|
150
168
|
rdoc_options: []
|
151
169
|
require_paths:
|
@@ -161,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
179
|
- !ruby/object:Gem::Version
|
162
180
|
version: '0'
|
163
181
|
requirements: []
|
164
|
-
rubygems_version: 3.1
|
182
|
+
rubygems_version: 3.0.3.1
|
165
183
|
signing_key:
|
166
184
|
specification_version: 4
|
167
|
-
summary:
|
185
|
+
summary: A monkey patch for ActiveRecord to prevent physical deletion.
|
168
186
|
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
|
-
|