soft_deletion 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Readme.md +1 -1
- data/lib/soft_deletion/core.rb +15 -13
- data/lib/soft_deletion/dependency.rb +3 -2
- data/lib/soft_deletion/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33929145814e0bfca2a2ae9fe549f6e333e298ceae93eab756f2590e32ea9879
|
4
|
+
data.tar.gz: 32f843e02d0d918e7ad6c15c609babba2832b04e1e8cf4c32d88eb75e5bd489b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 634ed1c15d3cd31744dbfa75f0df013decb6e1e27157a59224c3ffdf5bfc2f1b75db2643639b92b8099c96dc6e71be98543765e3640e1c933314ad3f59704ced
|
7
|
+
data.tar.gz: a02f8debc86470ef9793e833e1900dedd8d3374c10db8b0808ca38abe04a30f0919de5d5b45d5543d0c9d47fa011b7025ab1288e09f74bfe75b104906f0ef4e3
|
data/Readme.md
CHANGED
@@ -26,7 +26,7 @@ end
|
|
26
26
|
# soft delete them including all soft-deletable dependencies that are marked as :destroy, :delete_all, :nullify
|
27
27
|
user = User.first
|
28
28
|
user.products.count == 10
|
29
|
-
user.soft_delete!
|
29
|
+
user.soft_delete!(validate: false)
|
30
30
|
user.deleted? # true
|
31
31
|
|
32
32
|
# use special with_deleted scope to find them ...
|
data/lib/soft_deletion/core.rb
CHANGED
@@ -53,7 +53,7 @@ module SoftDeletion
|
|
53
53
|
end
|
54
54
|
|
55
55
|
models.each do |model|
|
56
|
-
model.soft_delete_dependencies.each(
|
56
|
+
model.soft_delete_dependencies.each { |dep| dep.execute_soft_delete(:soft_delete!, []) }
|
57
57
|
model.run_callbacks :soft_delete
|
58
58
|
end
|
59
59
|
end
|
@@ -73,11 +73,11 @@ module SoftDeletion
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def soft_delete!(*args)
|
76
|
-
_run_soft_delete { save!(*args) } || soft_delete_hook_failed(:before_soft_delete)
|
76
|
+
_run_soft_delete(:soft_delete!, args) { save!(*args) } || soft_delete_hook_failed(:before_soft_delete)
|
77
77
|
end
|
78
78
|
|
79
79
|
def soft_delete(*args)
|
80
|
-
_run_soft_delete{ save(*args) }
|
80
|
+
_run_soft_delete(:soft_delete, args) { save(*args) }
|
81
81
|
end
|
82
82
|
|
83
83
|
def soft_undelete
|
@@ -111,19 +111,21 @@ module SoftDeletion
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
def _run_soft_delete(&block)
|
114
|
+
def _run_soft_delete(method, args, &block)
|
115
115
|
result = false
|
116
|
-
internal = lambda do
|
117
|
-
mark_as_deleted
|
118
|
-
soft_delete_dependencies.each(&:soft_delete!)
|
119
|
-
result = block.call
|
120
|
-
update_soft_delete_counter_caches(-1)
|
121
|
-
end
|
122
|
-
|
123
116
|
self.class.transaction do
|
117
|
+
internal = lambda do
|
118
|
+
mark_as_deleted
|
119
|
+
raise ActiveRecord::Rollback unless soft_delete_dependencies.all? { |dep| dep.execute_soft_delete(method, args) }
|
120
|
+
result = block.call
|
121
|
+
raise ActiveRecord::Rollback unless result
|
122
|
+
update_soft_delete_counter_caches(-1)
|
123
|
+
end
|
124
|
+
|
124
125
|
run_callbacks :soft_delete, &internal
|
125
|
-
end
|
126
126
|
|
127
|
+
result
|
128
|
+
end
|
127
129
|
result
|
128
130
|
end
|
129
131
|
|
@@ -134,7 +136,7 @@ module SoftDeletion
|
|
134
136
|
limit = deleted_at - 1.hour
|
135
137
|
internal = lambda do
|
136
138
|
mark_as_undeleted
|
137
|
-
soft_delete_dependencies.each { |m| m.soft_undelete!(limit)}
|
139
|
+
soft_delete_dependencies.each { |m| m.soft_undelete!(limit) }
|
138
140
|
result = block.call
|
139
141
|
update_soft_delete_counter_caches(1)
|
140
142
|
end
|
@@ -7,14 +7,15 @@ module SoftDeletion
|
|
7
7
|
@association_name = association_name
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def execute_soft_delete(method, args)
|
11
11
|
case association.options[:dependent]
|
12
12
|
when :nullify
|
13
13
|
nullify_dependencies
|
14
14
|
when :delete_all
|
15
15
|
dependency.update_all(dependency.mark_as_soft_deleted_sql)
|
16
|
+
true
|
16
17
|
else
|
17
|
-
dependencies.
|
18
|
+
dependencies.all? { |dep| dep.send(method, *args) }
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soft_deletion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zendesk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
requirements: []
|
176
176
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.
|
177
|
+
rubygems_version: 2.7.4
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Explicit soft deletion for ActiveRecord via deleted_at and default scope.
|