soft_deletion 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +2 -0
- data/lib/soft_deletion/core.rb +19 -0
- data/lib/soft_deletion/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1865ab76d9db34c7e26eb92400a99b31180e3e2
|
4
|
+
data.tar.gz: e9123420db3c2e6f6cbf1cdf846d4d540ce85d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86ffdda398270cf731fadfd7fb4c90524885559643e8c108181b9344209e132fbf953960feb8d31b5dd9aefa2dffa063856ad0e0024d0f0e10e0c6ea7a347ded
|
7
|
+
data.tar.gz: 07d2e6b5ee0d8187df14c8aa5e38a6b6b236cb1ed3616d3b6bafae1e1e7d364f773dc8f32f3ab5de4dfc0fcfb64ae9a64263355a2b07cf2e81e10eb9f015c74a
|
data/Readme.md
CHANGED
data/lib/soft_deletion/core.rb
CHANGED
@@ -94,12 +94,30 @@ module SoftDeletion
|
|
94
94
|
|
95
95
|
protected
|
96
96
|
|
97
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
98
|
+
def each_counter_cached_associations
|
99
|
+
reflections.each do |name, reflection|
|
100
|
+
yield association(name.to_sym) if reflection.belongs_to? && reflection.counter_cache_column
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def update_soft_delete_counter_caches(value)
|
106
|
+
each_counter_cached_associations do |association|
|
107
|
+
if association.target
|
108
|
+
target = association.target
|
109
|
+
target.class.update_counters(target.id, association.reflection.counter_cache_column => value)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
97
114
|
def _run_soft_delete(&block)
|
98
115
|
result = false
|
99
116
|
internal = lambda do
|
100
117
|
mark_as_deleted
|
101
118
|
soft_delete_dependencies.each(&:soft_delete!)
|
102
119
|
result = block.call
|
120
|
+
update_soft_delete_counter_caches(-1)
|
103
121
|
end
|
104
122
|
|
105
123
|
self.class.transaction do
|
@@ -118,6 +136,7 @@ module SoftDeletion
|
|
118
136
|
mark_as_undeleted
|
119
137
|
soft_delete_dependencies.each { |m| m.soft_undelete!(limit)}
|
120
138
|
result = block.call
|
139
|
+
update_soft_delete_counter_caches(1)
|
121
140
|
end
|
122
141
|
|
123
142
|
self.class.transaction do
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zendesk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -128,6 +128,20 @@ dependencies:
|
|
128
128
|
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: byebug
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
131
145
|
description:
|
132
146
|
email: michael@grosser.it
|
133
147
|
executables: []
|