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: bb3fef2b82bccaa79965f493c0e8daa2e1f943fba503858bc950fb69fc81360a
4
- data.tar.gz: 25ea760393d9412968a8473ab2fe876c82d2389d21154b22e9db5a58ffe0cc88
3
+ metadata.gz: 86a87d0163261f63b8c5e0275032146d7fd493afd8bdeb189a0a494f4a8c17d6
4
+ data.tar.gz: 48f0a91d6dbd4694fdcc6a89560b03f11d40a72e41d65318dba9e4d394b62ea0
5
5
  SHA512:
6
- metadata.gz: 314aee638ef81c03e9f6188ee5dd5b7ae022befd232e2e4e0d667bee310d2375dd81f679093b76b2e0416600a2cc3c045f035d734ca8b9dbff91dd4e20caebf2
7
- data.tar.gz: 85df0799d1e2731e3518ce310a3e10fce24776eba0b6a7802fb76ef389994d9db75cfbc8166211f1bc08c5bce3e1854b905160aef43321e5bd22b467eccf3f51
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
- ### Specify where the cache will be stored
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.send(@column) if binding.is_a?(::ActiveRecord::Base)
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 = @model.send(attr.column).try(primary_key)
48
+ data = get_target.call.try(primary_key)
48
49
  else
49
- bindings << @model.send(attr.column) if @model.is_a?(::ActiveRecord::Base)
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveModelCachers
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_cachers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy