guard_against_physical_delete 1.0.0 → 2.1.0

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: e4f57f099c2f498d498bc4080d1241c0ca4973cc
4
- data.tar.gz: 766a9b52dbea30d3d2208da40eeb83dac8f1ffc6
2
+ SHA256:
3
+ metadata.gz: a37d0705c44bfcae06881a4815abb159ea31d8fd65bb805a4f511c694f2351ea
4
+ data.tar.gz: 143cf811443a35dce054b0db4751f51760d2ac8e15c738f38db11ac97b84214a
5
5
  SHA512:
6
- metadata.gz: 44ca59e3608e8d8752095629dabdecb5fcfc9e5be8683490569629aa339d94edfb3b7472765937f49558c8a4ce2d92de7c573120762b8182b46d9cbca4473ffc
7
- data.tar.gz: 9fb8466de8aa5b87275590a8f185a68757534407b0ad56864906b91ffd06961ed635a14197fe78ec39336216ddb67072cfa7612ccf1737c0e854b9bcc3e0fcd0
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
@@ -1,4 +1,5 @@
1
1
  .bundle
2
2
  test.db
3
3
  coverage
4
- Gemfile.lock
4
+ pkg
5
+ rdoc
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/Rakefile CHANGED
@@ -1,48 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "guard_against_physical_delete"
18
- gem.homepage = "http://github.com/cookpad/guard_against_physical_delete"
19
- #gem.license = "MIT"
20
- gem.summary = "Guard against physical delete"
21
- gem.description = "Guard against physical delete"
22
- gem.email = "morita@cookpad.com"
23
- gem.authors = ["MORITA shingo"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
-
29
- Dir['lib/tasks/*.rake'].each { |rake| load rake }
3
+ require 'bundler/gem_tasks'
30
4
 
31
- require 'rspec/core'
32
5
  require 'rspec/core/rake_task'
33
6
 
34
7
  RSpec::Core::RakeTask.new(:spec)
35
8
 
36
9
  task :default => :spec
37
10
 
38
- desc "Run all specs with rcov"
39
- RSpec::Core::RakeTask.new(:rcov) do |t|
40
- t.rcov = true
41
- t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/}
42
- end
43
-
44
- task :default => :spec
45
-
46
11
  require 'rdoc/task'
47
12
  Rake::RDocTask.new do |rdoc|
48
13
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
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.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,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.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,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.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,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.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
@@ -1,54 +1,32 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
3
+ require_relative "lib/guard_against_physical_delete/version"
4
+
6
5
  Gem::Specification.new do |s|
7
6
  s.name = "guard_against_physical_delete"
8
- s.version = "1.0.0"
7
+ s.version = GuardAgainstPhysicalDelete::VERSION
9
8
 
10
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
10
  s.authors = ["MORITA shingo"]
12
11
  s.date = "2012-03-06"
13
- s.description = "Guard against physical delete"
14
12
  s.email = "morita@cookpad.com"
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
13
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
19
14
  s.homepage = "http://github.com/cookpad/guard_against_physical_delete"
20
15
  s.require_paths = ["lib"]
21
16
  s.rubygems_version = "1.8.15"
22
- s.summary = "Guard against physical delete"
17
+ s.summary = "A monkey patch for ActiveRecord to prevent physical deletion."
23
18
 
24
- if s.respond_to? :specification_version then
25
- s.specification_version = 3
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
26
22
 
27
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<activerecord>, [">= 3.0.10"])
29
- s.add_development_dependency(%q<rspec>, [">= 0"])
30
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
31
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
32
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
33
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
34
- s.add_development_dependency(%q<database_cleaner>, [">= 0"])
35
- else
36
- s.add_dependency(%q<activerecord>, [">= 3.0.10"])
37
- s.add_dependency(%q<rspec>, [">= 0"])
38
- s.add_dependency(%q<sqlite3>, [">= 0"])
39
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
40
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
41
- s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
42
- s.add_dependency(%q<database_cleaner>, [">= 0"])
43
- end
44
- else
45
- s.add_dependency(%q<activerecord>, [">= 3.0.10"])
46
- s.add_dependency(%q<rspec>, [">= 0"])
47
- s.add_dependency(%q<sqlite3>, [">= 0"])
48
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
49
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
- s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
51
- s.add_dependency(%q<database_cleaner>, [">= 0"])
52
- end
23
+ s.add_runtime_dependency "activerecord", ">= 5", "< 6.1"
24
+ s.add_development_dependency "rake", "~> 13"
25
+ s.add_development_dependency "rspec", "~> 3"
26
+ s.add_development_dependency "sqlite3", "~> 1.4"
27
+ s.add_development_dependency "bundler"
28
+ s.add_development_dependency "database_cleaner"
29
+ s.add_development_dependency "simplecov"
30
+ s.add_development_dependency "countdownlatch"
53
31
  end
54
32
 
@@ -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? && 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
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.0"
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.0
4
+ version: 2.1.0
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,86 +16,106 @@ 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.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
- version: 3.0.10
29
+ version: '5'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.1'
27
33
  - !ruby/object:Gem::Dependency
28
- name: rspec
34
+ name: rake
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '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: '0'
46
+ version: '13'
41
47
  - !ruby/object:Gem::Dependency
42
- name: sqlite3
48
+ name: rspec
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - ">="
51
+ - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0'
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: '0'
60
+ version: '3'
55
61
  - !ruby/object:Gem::Dependency
56
- name: rdoc
62
+ name: sqlite3
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '3.12'
67
+ version: '1.4'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '3.12'
74
+ version: '1.4'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: bundler
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - "~>"
79
+ - - ">="
74
80
  - !ruby/object:Gem::Version
75
- version: 1.0.0
81
+ version: '0'
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
- - - "~>"
86
+ - - ">="
81
87
  - !ruby/object:Gem::Version
82
- version: 1.0.0
88
+ version: '0'
83
89
  - !ruby/object:Gem::Dependency
84
- name: jeweler
90
+ name: database_cleaner
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - "~>"
93
+ - - ">="
88
94
  - !ruby/object:Gem::Version
89
- version: 1.8.3
95
+ version: '0'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - "~>"
100
+ - - ">="
95
101
  - !ruby/object:Gem::Version
96
- version: 1.8.3
102
+ version: '0'
97
103
  - !ruby/object:Gem::Dependency
98
- name: database_cleaner
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: countdownlatch
99
119
  requirement: !ruby/object:Gem::Requirement
100
120
  requirements:
101
121
  - - ">="
@@ -108,33 +128,43 @@ dependencies:
108
128
  - - ">="
109
129
  - !ruby/object:Gem::Version
110
130
  version: '0'
111
- description: Guard against physical delete
131
+ description:
112
132
  email: morita@cookpad.com
113
133
  executables: []
114
134
  extensions: []
115
- extra_rdoc_files:
116
- - README.rdoc
135
+ extra_rdoc_files: []
117
136
  files:
137
+ - ".github/workflows/master_and_pr.yml"
118
138
  - ".gitignore"
119
- - ".travis.yml"
120
- - Gemfile
139
+ - CHANGELOG.md
121
140
  - License.txt
122
- - README.rdoc
141
+ - README.md
123
142
  - Rakefile
124
- - VERSION
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
125
153
  - guard_against_physical_delete.gemspec
126
154
  - lib/guard_against_physical_delete.rb
127
155
  - lib/guard_against_physical_delete/base.rb
128
156
  - lib/guard_against_physical_delete/physical_delete_error.rb
129
157
  - lib/guard_against_physical_delete/relation.rb
130
158
  - lib/guard_against_physical_delete/support_counter_cache.rb
131
- - lib/guard_against_physical_delete/support_counter_cache/3.0.10/associations.rb
132
- - lib/guard_against_physical_delete/support_counter_cache/3.2_and_4.0/associations/builder/belongs_to.rb
133
159
  - lib/guard_against_physical_delete/support_counter_cache/associations/builder/belongs_to.rb
160
+ - lib/guard_against_physical_delete/version.rb
134
161
  homepage: http://github.com/cookpad/guard_against_physical_delete
135
162
  licenses: []
136
- metadata: {}
137
- post_install_message:
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
167
+ post_install_message:
138
168
  rdoc_options: []
139
169
  require_paths:
140
170
  - lib
@@ -149,9 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
179
  - !ruby/object:Gem::Version
150
180
  version: '0'
151
181
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.4.5.1
154
- signing_key:
155
- specification_version: 3
156
- summary: Guard against physical delete
182
+ rubygems_version: 3.0.3.1
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: A monkey patch for ActiveRecord to prevent physical deletion.
157
186
  test_files: []
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.8.7
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
data/Gemfile DELETED
@@ -1,20 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- gem 'activerecord', '>= 3.0.10'
9
- gem "bundler"
10
-
11
- group :development do
12
- gem 'sqlite3'
13
- gem "rdoc", "~> 3.12"
14
- gem "jeweler", "~> 1.8.3"
15
- gem 'database_cleaner'
16
-
17
- gem 'rspec', '< 2.99'
18
- gem 'simplecov', :platforms => [:ruby_19, :ruby_20, :ruby_21]
19
- gem 'countdownlatch'
20
- end
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
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1
@@ -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