active_tools 0.0.35 → 0.0.36
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d599d581dac5166f36e4b607305fa5891d958ba
|
4
|
+
data.tar.gz: 55fb1d88e0ec5e3974d357e6d99a3df2d0ef34eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8b99b36d0c0024bee898599eda063fe0db6bcb38e02d69edfb811a36a3dbb629152e2cee7f900ce9fc52df15569553815e5c89cebe02907a16bcece4e1d0f36
|
7
|
+
data.tar.gz: d9251e91a3e6b6933574f04f6661891aa91074235acb2fb9b7cbe079f9121b43fc45f1f70158cc138e5258ee381661716f20f89374d98ab4a8001ed37c919eaa
|
@@ -3,7 +3,7 @@ module ActiveTools
|
|
3
3
|
module CustomCounterCache
|
4
4
|
module InstanceMethods
|
5
5
|
def custom_counter_cache_after_create(assoc_name, reflection, assoc_mapping)
|
6
|
-
if record =
|
6
|
+
if record = try(assoc_name)
|
7
7
|
ActiveRecord::CustomCounterCache.digger(self, record, assoc_mapping) do |parent, cache_column, value|
|
8
8
|
parent.class.update_counters(parent.id, cache_column => value)
|
9
9
|
end
|
@@ -13,7 +13,7 @@ module ActiveTools
|
|
13
13
|
|
14
14
|
def custom_counter_cache_before_destroy(assoc_name, reflection, assoc_mapping)
|
15
15
|
unless destroyed_by_association && (destroyed_by_association.foreign_key.to_sym == reflection.foreign_key.to_sym)
|
16
|
-
if (record =
|
16
|
+
if (record = try(assoc_name)) && !self.destroyed?
|
17
17
|
ActiveRecord::CustomCounterCache.digger(self, record, assoc_mapping) do |parent, cache_column, value|
|
18
18
|
parent.class.update_counters(parent.id, cache_column => -value)
|
19
19
|
end
|
@@ -21,23 +21,23 @@ module ActiveTools
|
|
21
21
|
else
|
22
22
|
assoc_mapping = value
|
23
23
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
reflection = reflections[assoc_name.to_s]
|
25
|
+
|
26
|
+
unless method_defined? :custom_counter_cache_after_create
|
27
|
+
include ActiveRecord::CustomCounterCache::InstanceMethods
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
after_create lambda { |record|
|
31
|
+
record.custom_counter_cache_after_create(assoc_name, reflection, assoc_mapping)
|
32
|
+
}
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
before_destroy lambda { |record|
|
35
|
+
record.custom_counter_cache_before_destroy(assoc_name, reflection, assoc_mapping)
|
36
|
+
}
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
38
|
+
after_update lambda { |record|
|
39
|
+
record.custom_counter_cache_after_update(assoc_name, reflection, assoc_mapping)
|
40
|
+
}
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -15,7 +15,7 @@ module ActiveTools
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
else
|
18
|
-
response = try(
|
18
|
+
response = try(method)
|
19
19
|
yield self, method, response, value
|
20
20
|
if value.is_a?(Hash) && !response.nil?
|
21
21
|
response.method_digger(value, &block)
|
@@ -27,7 +27,7 @@ module ActiveTools
|
|
27
27
|
def cycle_call(method, &block)
|
28
28
|
object = self
|
29
29
|
export = []
|
30
|
-
while object = object.try(
|
30
|
+
while object = object.try(method)
|
31
31
|
yield object if block_given?
|
32
32
|
export << object
|
33
33
|
end
|
data/lib/active_tools/version.rb
CHANGED