active_model_cachers 2.0.0 → 2.0.1
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a87d0163261f63b8c5e0275032146d7fd493afd8bdeb189a0a494f4a8c17d6
|
4
|
+
data.tar.gz: 48f0a91d6dbd4694fdcc6a89560b03f11d40a72e41d65318dba9e4d394b62ea0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6b80679ae29bd12fa299c3bd88785489c310ed82130ecae9bbe5e8850ecd5050154651a8428eca9b4cd22d8da815b919cd803920cd1aa007a432a60ff359605
|
7
|
+
data.tar.gz: b9d588a0cafdabdb49207a81fbc63f8e915570a17196e5fcecbc96924cf1cefcf661ed3bb1f90d68963e91ea768104a44bb36d02a59d2624adaf400303c65466
|
data/README.md
CHANGED
@@ -30,12 +30,11 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
$ gem install active_model_cachers
|
32
32
|
|
33
|
-
|
33
|
+
Add an initializer with this code to your project:
|
34
34
|
|
35
|
-
Add the following to your environment files (production.rb, development.rb, test.rb):
|
36
35
|
```rb
|
37
36
|
ActiveModelCachers.config do |config|
|
38
|
-
config.store = Rails.cache
|
37
|
+
config.store = Rails.cache # specify where the cache will be stored
|
39
38
|
end
|
40
39
|
```
|
41
40
|
|
@@ -83,7 +83,7 @@ module ActiveModelCachers
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def query_association(binding, id)
|
86
|
-
return binding.
|
86
|
+
return binding.association(@column).load_target if binding.is_a?(::ActiveRecord::Base)
|
87
87
|
id = @reflect.active_record.where(id: id).limit(1).pluck(foreign_key).first if foreign_key != 'id'
|
88
88
|
if @reflect.collection?
|
89
89
|
return id ? @reflect.klass.where(@reflect.foreign_key => id).to_a : []
|
@@ -43,10 +43,11 @@ module ActiveModelCachers
|
|
43
43
|
def exec_by(attr, primary_key, service_klasses, method)
|
44
44
|
bindings = [@model]
|
45
45
|
if @model and attr.association?
|
46
|
+
get_target = ->{ @model.association(attr.column).load_target }
|
46
47
|
if attr.has_one?
|
47
|
-
data =
|
48
|
+
data = get_target.call.try(primary_key)
|
48
49
|
else
|
49
|
-
bindings <<
|
50
|
+
bindings << get_target.call if method != :clean_cache # no need to load binding when just cleaning cache
|
50
51
|
end
|
51
52
|
end
|
52
53
|
data ||= (@model ? @model.send(primary_key) : nil) || @id
|