guard_against_physical_delete 1.0.2 → 2.1.1

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
- SHA1:
3
- metadata.gz: 02c2548cfaa8943a5e4a5daf8346e8eb9adb291b
4
- data.tar.gz: bd9b86a8934b5f991ed03ca4b3fa32afcc2e5d3d
2
+ SHA256:
3
+ metadata.gz: bf3003e9c60b6e19e0f13de9cfca5c1ccf85f8a5c33cbfb327bc60ead38c9332
4
+ data.tar.gz: 89f4cd9c51bb7bff0712215b6a5b503d7148b982694708a7a274423e59134a1b
5
5
  SHA512:
6
- metadata.gz: cc3c00bbdfa6c8c31be45d8ca7ee59f69d01cf5dda46c1931f2d3bd0301ab9e25c757281ccfe064c5d8e5882955433d723e690543388ef4ba8d566bd696cfa9b
7
- data.tar.gz: 8831b00d3ac1a863ef5e0f411322cca1ea2b0a46f44b3a2010849ff699811342c893ba433adcfef4660a48b38d1ead177d21cfc4e39d61b1aa0e43a4632db004
6
+ metadata.gz: 55d3b887dbaf294c6b262620dc24b0d7be5cf147798ad8899137121b6cce1fdb547569acfdd1cec363a3879b3dd5758396533cf8db2bc361fcdabe7492e1b2ae
7
+ data.tar.gz: b8e1c3941e184465eec596f0da8e8a662135c462bf5e42b66fbb4e5c1d52261407cb71b1433a4cd935efe8cc6ed78db826d23c61137092f2e981d91347246a4e
@@ -0,0 +1,30 @@
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
+ - "6.1"
20
+ name: Test on Rails ${{ matrix.rails_version }}
21
+ env:
22
+ BUNDLE_GEMFILE: gemfiles/Gemfile_rails_${{ matrix.rails_version }}.rb
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: 2.7
28
+ bundler-cache: true
29
+ - name: rspec
30
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -3,4 +3,3 @@ test.db
3
3
  coverage
4
4
  pkg
5
5
  rdoc
6
- Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 2.1.1 - 2022-05-26
6
+
7
+ ### Added
8
+
9
+ - Support activerecord 6.1.
10
+
11
+ ## 2.1.0 - 2021-12-02
12
+
13
+ ### Added
14
+
15
+ - Support activerecord 6.0.
16
+
17
+ ### Fixed
18
+
19
+ - Fix bug that it doesn't guard `#destroy` on activerecord 5.2.
20
+
21
+ ## 2.0.0 - 2021-08-04
22
+
23
+ ### Added
24
+
25
+ - Support activerecord 5.
26
+
27
+ ### Removed
28
+
29
+ - Drop support for ruby < 2.0.
30
+ - Drop support for activerecord < 5.
31
+
32
+ ## 1.0.2 - 2017-03-16
33
+
34
+ ## 1.0.1 - 2017-03-09
35
+
36
+ ### Fixed
37
+
38
+ - Fix files in gemspec.
39
+
40
+ ## 1.0.0 - 2017-03-09
41
+
42
+ ### Added
43
+
44
+ - 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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ for path in gemfiles/Gemfile_*.rb; do
7
+ BUNDLE_GEMFILE="${path}" bundle install
8
+ done
data/bin/test ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ for path in gemfiles/Gemfile_*.rb; do
7
+ BUNDLE_GEMFILE="${path}" bundle exec rspec
8
+ done
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activerecord', '~> 5.0.0'
6
+ gem 'sqlite3', '~> 1.3.0'
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ guard_against_physical_delete (2.1.0)
5
+ activerecord (>= 5, < 6.2)
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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activerecord', '~> 5.1.0'
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ guard_against_physical_delete (2.1.0)
5
+ activerecord (>= 5, < 6.2)
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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activerecord', '~> 5.2.0'
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ guard_against_physical_delete (2.1.0)
5
+ activerecord (>= 5, < 6.2)
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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activerecord', '~> 6.0.0'
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ guard_against_physical_delete (2.1.0)
5
+ activerecord (>= 5, < 6.2)
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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'activerecord', '~> 6.1.0'
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ guard_against_physical_delete (2.1.0)
5
+ activerecord (>= 5, < 6.2)
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
@@ -1,28 +1,29 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ require_relative "lib/guard_against_physical_delete/version"
4
+
3
5
  Gem::Specification.new do |s|
4
6
  s.name = "guard_against_physical_delete"
5
- s.version = "1.0.2"
7
+ s.version = GuardAgainstPhysicalDelete::VERSION
6
8
 
7
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
10
  s.authors = ["MORITA shingo"]
9
11
  s.date = "2012-03-06"
10
- s.description = "Guard against physical delete"
11
12
  s.email = "morita@cookpad.com"
12
- s.extra_rdoc_files = [
13
- "README.rdoc"
14
- ]
15
13
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
16
14
  s.homepage = "http://github.com/cookpad/guard_against_physical_delete"
17
15
  s.require_paths = ["lib"]
18
16
  s.rubygems_version = "1.8.15"
19
- s.summary = "Guard against physical delete"
17
+ s.summary = "A monkey patch for ActiveRecord to prevent physical deletion."
18
+
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
20
22
 
21
- s.add_runtime_dependency "activerecord", ">= 3.0.10"
22
- s.add_development_dependency "rake", "< 12.0"
23
- s.add_development_dependency "rspec", "< 2.99"
24
- s.add_development_dependency "sqlite3"
25
- s.add_development_dependency "rdoc", "~> 3.12"
23
+ s.add_runtime_dependency "activerecord", ">= 5", "< 6.2"
24
+ s.add_development_dependency "rake", "~> 13"
25
+ s.add_development_dependency "rspec", "~> 3"
26
+ s.add_development_dependency "sqlite3", "~> 1.4"
26
27
  s.add_development_dependency "bundler"
27
28
  s.add_development_dependency "database_cleaner"
28
29
  s.add_development_dependency "simplecov"
@@ -36,7 +36,7 @@ module GuardAgainstPhysicalDelete
36
36
  private
37
37
 
38
38
  THREAD_LOCAL_KEY = :__GuardAgainstPhysicalDelete__thread_local_permission__
39
- private_constant :THREAD_LOCAL_KEY if RUBY_VERSION >= '1.9.3'
39
+ private_constant :THREAD_LOCAL_KEY
40
40
 
41
41
  def physical_delete_permission
42
42
  Thread.current[THREAD_LOCAL_KEY] ||= Hash.new { |h,k| h[k] = 0 }
@@ -44,6 +44,16 @@ module GuardAgainstPhysicalDelete
44
44
  end
45
45
 
46
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
+
47
57
  def hard_delete
48
58
  self.class.physical_delete { destroy }
49
59
  end
@@ -1,15 +1,16 @@
1
1
  module GuardAgainstPhysicalDelete
2
2
  module Relation
3
- def self.included(obj)
4
- obj.class_eval do
5
- def delete_all_with_check_permit(conditions = nil)
6
- unless @klass.delete_permitted?
7
- raise GuardAgainstPhysicalDelete::PhysicalDeleteError, @klass.name
8
- end
9
- delete_all_without_check_permit(conditions)
3
+ def self.included(base)
4
+ base.prepend MethodOverrides
5
+ end
6
+
7
+ module MethodOverrides
8
+ def delete_all
9
+ unless klass.delete_permitted?
10
+ raise GuardAgainstPhysicalDelete::PhysicalDeleteError, klass.name
10
11
  end
11
12
 
12
- alias_method_chain :delete_all, :check_permit
13
+ super
13
14
  end
14
15
  end
15
16
  end
@@ -5,51 +5,62 @@ module GuardAgainstPhysicalDelete
5
5
  module BelongsTo
6
6
  def self.included(obj)
7
7
  class << obj
8
+ prepend MethodOverrides
9
+
8
10
  private
9
- def add_counter_cache_methods_with_logical_delete(mixin)
10
- add_counter_cache_methods_without_logical_delete mixin
11
- add_logical_delete_counter_cache_methods(mixin)
12
- end
13
- alias_method_chain :add_counter_cache_methods, :logical_delete
14
11
 
15
12
  def add_logical_delete_counter_cache_methods(mixin)
16
13
  mixin.class_eval do
17
- def belongs_to_counter_cache_after_logical_delete(reflection)
18
- cache_column = reflection.counter_cache_column
19
- delete_column = self.logical_delete_column
20
- return unless send("#{delete_column}_changed?")
21
- return unless send("#{delete_column}_was").nil?
22
-
23
- record = send(reflection.name)
24
- record.class.decrement_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
25
26
  end
26
27
 
27
- def belongs_to_counter_cache_after_revive(reflection)
28
- cache_column = reflection.counter_cache_column
29
- delete_column = self.logical_delete_column
30
- return unless send("#{delete_column}_changed?")
31
- return if send("#{delete_column}_was").nil?
32
- return unless send(delete_column).nil?
33
- record = send(reflection.name)
34
- record.class.increment_counter(cache_column, record.id) unless record.nil?
28
+ # Polyfill for Rails < 5.1, not that it's perfectly compatible.
29
+ if ActiveRecord.version < Gem::Version.new('5.1.0')
30
+ # @param [#to_s] attr_name
31
+ # @return [Object]
32
+ def attribute_before_last_save(attr_name)
33
+ __send__("#{attr_name}_was")
34
+ end
35
+
36
+ # @param [#to_s] attr_name
37
+ # @return [Boolean]
38
+ def saved_change_to_attribute?(attr_name)
39
+ __send__("#{attr_name}_changed?")
40
+ end
35
41
  end
36
42
  end
43
+
37
44
  mixin.redefine_method("belongs_to_counter_cache_after_update_for_#{name}") do
38
45
  # do nothing
39
46
  end if mixin.method_defined?("belongs_to_counter_cache_after_update_for_#{name}")
40
47
  end
48
+ end
49
+ end
50
+ end
41
51
 
42
- def add_counter_cache_callbacks_with_logical_delete(model, reflection)
43
- add_counter_cache_callbacks_without_logical_delete model, reflection
52
+ module MethodOverrides
53
+ private
44
54
 
45
- return unless model.logical_delete?
55
+ def add_counter_cache_callbacks(model, reflection)
56
+ super(model, reflection)
46
57
 
47
- model.after_update lambda { |record|
48
- record.belongs_to_counter_cache_after_logical_delete(reflection)
49
- record.belongs_to_counter_cache_after_revive(reflection)
50
- }
51
- end
52
- alias_method_chain :add_counter_cache_callbacks, :logical_delete
58
+ return unless model.logical_delete?
59
+
60
+ add_logical_delete_counter_cache_methods(model)
61
+
62
+ model.after_update -> record do
63
+ record.adjust_counter_caches_for_logical_deletion(reflection)
53
64
  end
54
65
  end
55
66
  end
@@ -1,12 +1 @@
1
- if ActiveRecord::VERSION::STRING >= "4.1"
2
- require 'guard_against_physical_delete/support_counter_cache/associations/builder/belongs_to'
3
- ActiveRecord::Associations::Builder::BelongsTo.send(:include, GuardAgainstPhysicalDelete::SupportCounterCache::Associations::Builder::BelongsTo)
4
- elsif ActiveRecord::VERSION::STRING >= "3.2"
5
- require 'guard_against_physical_delete/support_counter_cache/3.2_and_4.0/associations/builder/belongs_to'
6
- ActiveRecord::Associations::Builder::BelongsTo.send(:include, GuardAgainstPhysicalDelete::SupportCounterCache::Associations::Builder::BelongsTo)
7
- elsif ActiveRecord::VERSION::STRING == "3.0.10"
8
- require 'guard_against_physical_delete/support_counter_cache/3.0.10/associations'
9
- ActiveRecord::Base.send(:include, GuardAgainstPhysicalDelete::SupportCounterCache::Associations)
10
- else
11
- raise "guard_against_physical_delete doesn't support ActiveRecord version #{ActiveRecord::VERSION::STRING}"
12
- end
1
+ require 'guard_against_physical_delete/support_counter_cache/associations/builder/belongs_to'
@@ -0,0 +1,3 @@
1
+ module GuardAgainstPhysicalDelete
2
+ VERSION = "2.1.1"
3
+ end
@@ -2,10 +2,10 @@ require 'active_record'
2
2
  require 'guard_against_physical_delete/physical_delete_error'
3
3
  require 'guard_against_physical_delete/relation'
4
4
  require 'guard_against_physical_delete/base'
5
+ require 'guard_against_physical_delete/support_counter_cache'
5
6
 
6
7
  ActiveSupport.on_load :active_record do
7
8
  ActiveRecord::Base.send(:include, GuardAgainstPhysicalDelete::Base)
8
9
  ActiveRecord::Relation.send(:include, GuardAgainstPhysicalDelete::Relation)
9
-
10
- require 'guard_against_physical_delete/support_counter_cache'
10
+ ActiveRecord::Associations::Builder::BelongsTo.send(:include, GuardAgainstPhysicalDelete::SupportCounterCache::Associations::Builder::BelongsTo)
11
11
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard_against_physical_delete
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MORITA shingo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2012-03-06 00:00:00.000000000 Z
@@ -16,70 +16,62 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.10
19
+ version: '5'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.2'
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
- version: 3.0.10
29
+ version: '5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rake
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "<"
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '12.0'
39
+ version: '13'
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
- - - "<"
44
+ - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '12.0'
46
+ version: '13'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rspec
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "<"
51
+ - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '2.99'
53
+ version: '3'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - "<"
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '2.99'
60
+ version: '3'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: sqlite3
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rdoc
71
63
  requirement: !ruby/object:Gem::Requirement
72
64
  requirements:
73
65
  - - "~>"
74
66
  - !ruby/object:Gem::Version
75
- version: '3.12'
67
+ version: '1.4'
76
68
  type: :development
77
69
  prerelease: false
78
70
  version_requirements: !ruby/object:Gem::Requirement
79
71
  requirements:
80
72
  - - "~>"
81
73
  - !ruby/object:Gem::Version
82
- version: '3.12'
74
+ version: '1.4'
83
75
  - !ruby/object:Gem::Dependency
84
76
  name: bundler
85
77
  requirement: !ruby/object:Gem::Requirement
@@ -136,32 +128,45 @@ dependencies:
136
128
  - - ">="
137
129
  - !ruby/object:Gem::Version
138
130
  version: '0'
139
- description: Guard against physical delete
131
+ description:
140
132
  email: morita@cookpad.com
141
133
  executables: []
142
134
  extensions: []
143
- extra_rdoc_files:
144
- - README.rdoc
135
+ extra_rdoc_files: []
145
136
  files:
137
+ - ".github/workflows/master_and_pr.yml"
146
138
  - ".gitignore"
147
- - ".travis.yml"
148
- - Gemfile
139
+ - CHANGELOG.md
149
140
  - License.txt
150
- - README.rdoc
141
+ - README.md
151
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
152
155
  - guard_against_physical_delete.gemspec
153
156
  - lib/guard_against_physical_delete.rb
154
157
  - lib/guard_against_physical_delete/base.rb
155
158
  - lib/guard_against_physical_delete/physical_delete_error.rb
156
159
  - lib/guard_against_physical_delete/relation.rb
157
160
  - lib/guard_against_physical_delete/support_counter_cache.rb
158
- - lib/guard_against_physical_delete/support_counter_cache/3.0.10/associations.rb
159
- - lib/guard_against_physical_delete/support_counter_cache/3.2_and_4.0/associations/builder/belongs_to.rb
160
161
  - lib/guard_against_physical_delete/support_counter_cache/associations/builder/belongs_to.rb
162
+ - lib/guard_against_physical_delete/version.rb
161
163
  homepage: http://github.com/cookpad/guard_against_physical_delete
162
164
  licenses: []
163
- metadata: {}
164
- post_install_message:
165
+ metadata:
166
+ changelog_uri: http://github.com/cookpad/guard_against_physical_delete/blob/master/CHANGELOG.md
167
+ homepage_uri: http://github.com/cookpad/guard_against_physical_delete
168
+ source_code_uri: http://github.com/cookpad/guard_against_physical_delete
169
+ post_install_message:
165
170
  rdoc_options: []
166
171
  require_paths:
167
172
  - lib
@@ -176,9 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
181
  - !ruby/object:Gem::Version
177
182
  version: '0'
178
183
  requirements: []
179
- rubyforge_project:
180
- rubygems_version: 2.4.5.2
181
- signing_key:
184
+ rubygems_version: 3.3.7
185
+ signing_key:
182
186
  specification_version: 4
183
- summary: Guard against physical delete
187
+ summary: A monkey patch for ActiveRecord to prevent physical deletion.
184
188
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.0
5
- - 2.3.3
6
- - 2.2.6
7
- before_install: gem install bundler -v 1.14.6
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
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 3.0.10, >= 3.2
12
-
13
- == Copyright
14
-
15
- Copyright (c) 2012 morita shingo. See License.txt for
16
- further details.
17
-
@@ -1,43 +0,0 @@
1
- module GuardAgainstPhysicalDelete
2
- module SupportCounterCache
3
- module Associations
4
- def self.included(obj)
5
- class << obj
6
- def add_counter_cache_callbacks_with_logical_delete(reflection)
7
- add_counter_cache_callbacks_without_logical_delete(reflection)
8
- return unless logical_delete?
9
- add_logical_delete_counter_cache_callback(reflection)
10
- end
11
- alias_method_chain :add_counter_cache_callbacks, :logical_delete
12
-
13
- def add_logical_delete_counter_cache_callback(reflection)
14
- cache_column = reflection.counter_cache_column
15
-
16
- logical_delete_method_name = "belongs_to_counter_cache_before_logical_delete_for_#{reflection.name}".to_sym
17
- define_method(logical_delete_method_name) do
18
- delete_column = self.logical_delete_column
19
- next unless send("#{delete_column}_changed?")
20
- next unless send("#{delete_column}_was").nil?
21
- association = send(reflection.name)
22
- association.class.decrement_counter(cache_column, association.id) unless association.nil?
23
- end
24
-
25
- revive_method_name = "belongs_to_counter_cache_before_revive_for_#{reflection.name}".to_sym
26
- define_method(revive_method_name) do
27
- delete_column = self.logical_delete_column
28
- next unless send("#{delete_column}_changed?")
29
- next if send("#{delete_column}_was").nil?
30
- next unless send(delete_column).nil?
31
-
32
- clear_association_cache
33
- association = send(reflection.name)
34
- association.class.increment_counter(cache_column, association.id) unless association.nil?
35
- end
36
-
37
- before_update(logical_delete_method_name, revive_method_name)
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,50 +0,0 @@
1
- module GuardAgainstPhysicalDelete
2
- module SupportCounterCache
3
- module Associations
4
- module Builder
5
- module BelongsTo
6
- def self.included(obj)
7
- obj.class_eval do
8
- def add_counter_cache_callbacks_with_logical_delete(reflection)
9
- add_counter_cache_callbacks_without_logical_delete(reflection)
10
- return unless model.logical_delete?
11
- add_logical_delete_counter_cache_callback(reflection)
12
- end
13
- alias_method_chain :add_counter_cache_callbacks, :logical_delete
14
-
15
- def add_logical_delete_counter_cache_callback(reflection)
16
- cache_column = reflection.counter_cache_column
17
- name = self.name
18
-
19
- logical_delete_method_name = "belongs_to_counter_cache_after_logical_delete_for_#{name}".to_sym
20
- mixin.redefine_method(logical_delete_method_name) do
21
- delete_column = self.logical_delete_column
22
- next unless send("#{delete_column}_changed?")
23
- next unless send("#{delete_column}_was").nil?
24
- record = send(name)
25
- record.class.decrement_counter(cache_column, record.id) unless record.nil?
26
- end
27
-
28
- mixin.redefine_method("belongs_to_counter_cache_after_update_for_#{name}") do
29
- # do nothing
30
- end if mixin.method_defined?("belongs_to_counter_cache_after_update_for_#{name}")
31
-
32
- revive_method_name = "belongs_to_counter_cache_after_revive_for_#{name}".to_sym
33
-
34
- mixin.redefine_method(revive_method_name) do
35
- delete_column = self.logical_delete_column
36
- next unless send("#{delete_column}_changed?")
37
- next if send("#{delete_column}_was").nil?
38
- next unless send(delete_column).nil?
39
- record = send(name)
40
- record.class.increment_counter(cache_column, record.id) unless record.nil?
41
- end
42
- model.after_update(logical_delete_method_name, revive_method_name)
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end