custom_counter_cache 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -32,25 +32,26 @@ module CustomCounterCache::Model
|
|
32
32
|
cache_column = cache_column.to_sym
|
33
33
|
method_name = "callback_#{cache_column}".to_sym
|
34
34
|
reflection = reflect_on_association(association_id)
|
35
|
+
foreign_key = reflection.options[:foreign_key] || reflection.association_foreign_key
|
35
36
|
# define callback
|
36
37
|
define_method method_name do
|
37
38
|
# update old association
|
38
|
-
if send("#{
|
39
|
-
old_assoc_id = send("#{
|
39
|
+
if send("#{foreign_key}_changed?")
|
40
|
+
old_assoc_id = send("#{foreign_key}_was")
|
40
41
|
if ( old_assoc_id && old_assoc = reflection.klass.find(old_assoc_id))
|
41
42
|
old_assoc.send("update_#{cache_column}")
|
42
43
|
end
|
43
44
|
end
|
44
45
|
# update new association
|
45
|
-
new_assoc_id = send(
|
46
|
+
new_assoc_id = send(foreign_key)
|
46
47
|
if ( new_assoc_id && new_assoc = reflection.klass.find(new_assoc_id) )
|
47
48
|
new_assoc.send("update_#{cache_column}")
|
48
49
|
end
|
49
50
|
end
|
50
51
|
# set callbacks
|
51
52
|
after_create method_name
|
52
|
-
after_update method_name, :if => options
|
53
|
-
after_destroy method_name, :if => options
|
53
|
+
after_update method_name, :if => options[:if]
|
54
|
+
after_destroy method_name, :if => options[:if]
|
54
55
|
end
|
55
56
|
|
56
57
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom_counter_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Cedric Howe
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-03-07 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements: []
|
80
80
|
|
81
81
|
rubyforge_project: custom_counter_cache
|
82
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.6.2
|
83
83
|
signing_key:
|
84
84
|
specification_version: 3
|
85
85
|
summary: Custom counter_cache functionality that supports conditions and multiple models.
|