active_archive 4.0.6 → 4.0.7

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: 92c1e713b49eefb44aeb6add213b87c81de0225d
4
- data.tar.gz: 6c5106eff7503054c0793240d47a184c0463a713
3
+ metadata.gz: 5092866dde1665b90ef7990da9caf0d876daec7c
4
+ data.tar.gz: 6ea0affb05227176e452ee64619ae618b0d1550f
5
5
  SHA512:
6
- metadata.gz: '0369966d50e4af17708b1756466a6dce60afa64f061eeab2d56798b83679a8dc1be9764e7b18a171dd6a3511b60c919112f2ccdface89c4f04707478a30e0b88'
7
- data.tar.gz: 69e4a6ccf751be3252291e924780d076f185cfafd4d542fc4c14e19d092b73821b5842843c6610a719ac75148f23e4325088f687f1605c47da62f23395efb75e
6
+ metadata.gz: a616c28a17e305a010cc0ed56941f6961b192dcf7d0e55f6dba329ed27aa7b026e49c7ff7ff3a3efe344d4567fba2d5881311134ada9767d3066f4013fa55ca0
7
+ data.tar.gz: d88833a0cdffce65f24898d0cba0e086362dd52050c881c623f0b078bcd8f2f5b91c7808f4381474c69885bfedc88ae0659c7ec3e1fe870f7cfea56b53239e88
@@ -60,13 +60,35 @@ module ActiveArchive
60
60
 
61
61
  def destroy_with_active_archive(force = nil)
62
62
  run_callbacks(:destroy) do
63
- archived? || new_record? ? save : set_archived_at(Time.now, force)
63
+ if archived? || new_record?
64
+ save
65
+ else
66
+ set_archived_at(Time.now, force)
67
+ each_counter_cache do |assoc_class, counter_cache_column, assoc_id|
68
+ assoc_class.decrement_counter(counter_cache_column, assoc_id)
69
+ end
70
+ end
64
71
  return(true)
65
72
  end
66
73
 
67
74
  archived? ? self : false
68
75
  end
69
76
 
77
+ def each_counter_cache
78
+ _reflections.each do |name, reflection|
79
+ next unless respond_to?(name.to_sym)
80
+
81
+ association = send(name.to_sym)
82
+
83
+ next if association.nil?
84
+ next unless reflection.belongs_to? && reflection.counter_cache_column
85
+
86
+ associated_class = association.class
87
+
88
+ yield(associated_class, reflection.counter_cache_column, send(reflection.foreign_key))
89
+ end
90
+ end
91
+
70
92
  def retrieve_archived_record
71
93
  self.class.unscoped.find(id)
72
94
  end
@@ -114,6 +136,9 @@ module ActiveArchive
114
136
  lambda do |validate|
115
137
  run_callbacks(:unarchive) do
116
138
  set_archived_at(nil, validate)
139
+ each_counter_cache do |assoc_class, counter_cache_column, assoc_id|
140
+ assoc_class.increment_counter(counter_cache_column, assoc_id)
141
+ end
117
142
  return(true)
118
143
  end
119
144
  end
@@ -151,7 +176,11 @@ module ActiveArchive
151
176
 
152
177
  begin
153
178
  should_ignore_validations?(force) ? record.save(validate: false) : record.save!
179
+
180
+ @previous_mutation_tracker = record.send(:previous_mutation_tracker)
181
+ @changed_attributes = HashWithIndifferentAccess.new
154
182
  @attributes = record.instance_variable_get('@attributes')
183
+ @mutation_tracker = nil
155
184
  rescue => error
156
185
  record.destroy
157
186
  raise(error)
@@ -1,3 +1,3 @@
1
1
  module ActiveArchive
2
- VERSION = '4.0.6'.freeze
2
+ VERSION = '4.0.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_archive
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-27 00:00:00.000000000 Z
11
+ date: 2017-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails