shadow_model 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shadow_model/associations/has_many.rb +5 -5
- data/lib/shadow_model/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a440b755047339d9c19cb083d67e6a850c1daf1b
|
4
|
+
data.tar.gz: 6f089365819678b32129e3e28a8b87cc5b13c6c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37f50a5bae551d95d019f739abadddd804bc6ffe61dac2c62a16cf632c046d3ecddbf53e9b7c6ce85db8fc39035fa72bb5de39bfa451a3966b736932e212a86c
|
7
|
+
data.tar.gz: 7322e40d43c14aee65124ad30dd454a5bb6769dc2024f9ee3df7891e657e565ccedb7196b27d32642bfb760a201818fc490ff68b56811f1a7e9e21bd720b35bc
|
@@ -11,7 +11,7 @@ class ::ActiveRecord::Associations::Builder::HasMany
|
|
11
11
|
def build_with_shadow_option
|
12
12
|
reflection = build_without_shadow_option
|
13
13
|
if options[:shadow]
|
14
|
-
model_name = model.
|
14
|
+
model_name = model.name.tr('::', '').underscore
|
15
15
|
model.class_eval <<-RUBY
|
16
16
|
def #{name}_shadow_cache_key
|
17
17
|
"#{model_name}_\#{self[self.class.primary_key]}_#{name}_shadow_cache"
|
@@ -30,20 +30,20 @@ class ::ActiveRecord::Associations::Builder::HasMany
|
|
30
30
|
RUBY
|
31
31
|
|
32
32
|
reflection.klass.class_eval <<-RUBY
|
33
|
-
after_save :
|
34
|
-
after_destroy :
|
33
|
+
after_save :update_shadow_cache_of_#{model_name}
|
34
|
+
after_destroy :delete_shadow_cache_of_#{model_name}
|
35
35
|
|
36
36
|
def belongs_to_#{model_name}_shadow_cache_key
|
37
37
|
"#{model_name}_\#{self[:#{reflection.foreign_key}]}_#{name}_shadow_cache"
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def update_shadow_cache_of_#{model_name}
|
41
41
|
cache_key = belongs_to_#{model_name}_shadow_cache_key
|
42
42
|
Redis.current.hset(cache_key, self[self.class.primary_key], self.build_shadow_data)
|
43
43
|
update_expiration(cache_key)
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def delete_shadow_cache_of_#{model_name}
|
47
47
|
Redis.current.hdel(belongs_to_#{model_name}_shadow_cache_key, self[self.class.primary_key])
|
48
48
|
end
|
49
49
|
RUBY
|
data/lib/shadow_model/version.rb
CHANGED