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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 855e30bb57aed54bfc4f5dad35add6d1e4016adf
4
- data.tar.gz: ddbd760ed9411b44d2b9108b189201976e7b7157
3
+ metadata.gz: f1865ab76d9db34c7e26eb92400a99b31180e3e2
4
+ data.tar.gz: e9123420db3c2e6f6cbf1cdf846d4d540ce85d1e
5
5
  SHA512:
6
- metadata.gz: 74ab08e62c1364f560b4d9c101ab0523ded919eb564fd5fb90dd5abcc269bb91ca4fac1900bc2a9bbe6eb59048987c41b34060d730655dd8a4ad5921dbb2d392
7
- data.tar.gz: 7149e993a547f9ab9747364b2da31616e9029ffd5164d78888d0ee731ae5fd641b4f03fd6d2844245d347d9ed983cf707729b5ce03bd9c09c64349c54ee7213b
6
+ metadata.gz: 86ffdda398270cf731fadfd7fb4c90524885559643e8c108181b9344209e132fbf953960feb8d31b5dd9aefa2dffa063856ad0e0024d0f0e10e0c6ea7a347ded
7
+ data.tar.gz: 07d2e6b5ee0d8187df14c8aa5e38a6b6b236cb1ed3616d3b6bafae1e1e7d364f773dc8f32f3ab5de4dfc0fcfb64ae9a64263355a2b07cf2e81e10eb9f015c74a
data/Readme.md CHANGED
@@ -36,6 +36,8 @@ User.with_deleted do
36
36
  user.products.count == 0
37
37
  end
38
38
 
39
+ # Do NOT use on assocations: Account.first.users.with_deleted {
40
+
39
41
  # soft undelete them all
40
42
  user.soft_undelete!
41
43
  user.products.count == 10
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SoftDeletion
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
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.1.0
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-04-28 00:00:00.000000000 Z
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: []