active_model_cachers 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8f1049480902351ca775b8682a51f49f580d42eb
4
- data.tar.gz: a26eef63dd1c0a799d6d91ec81b468bc27c18cc2
2
+ SHA256:
3
+ metadata.gz: 8c49c9bc175d4ab55f5507cc4a6c4db006a099c90819e71788ced4b799d510f9
4
+ data.tar.gz: bb19f0043d46963c75b4ef71d30945c35156acb778b19d3f72e874b6c6dbdd15
5
5
  SHA512:
6
- metadata.gz: 3f9dd545f78b1f6531ea09f340edcd4b00b15571825f325467745e00573f35f42688d86c6504d9953b029e0868b368094d460bf854f675a581398377e88e93f6
7
- data.tar.gz: d2cd5b03a2ba48ee110e04fb30e5b4f2c5a41827af4f2a426b150ad3971967aac6c9cdc53e2f7c7417de06ff5b280daac24daeacc54ffd9caf199191c3582cfb
6
+ metadata.gz: 478355a8ee8fed5b1a25fcb6c2ef258888f6507c8e6bc74e98b9c559470b9475b750e69c7e03a7f77b05324cfc7927076e3c6173e08d0dbe4e4247283ab87011
7
+ data.tar.gz: c2029fb1379a12f03669b9a7dfa09858ab96a3cba755074ed1483e5a5239a890cd1c33dc9bfaf2973e7b76f5d1f42b166bb9a51b27e4c958d727d137d27437e4
data/.travis.yml CHANGED
@@ -13,6 +13,7 @@ gemfile:
13
13
  - gemfiles/4.2.gemfile
14
14
  - gemfiles/5.0.gemfile
15
15
  - gemfiles/5.1.gemfile
16
+ - gemfiles/5.2.gemfile
16
17
  addons:
17
18
  code_climate:
18
19
  repo_token: 02a53f73b72a95af756b1c0270d4b22a6f07d25a1c65048e341371e7b72671d9
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "activerecord", "~> 5.2.0"
4
+ gem "request_store", "~> 1.4.0"
5
+
6
+ group :test do
7
+ gem "simplecov"
8
+ gem "codeclimate-test-reporter", "~> 1.0.0"
9
+ end
10
+
11
+ gemspec :path => "../"
12
+
@@ -73,13 +73,6 @@ module ActiveModelCachers
73
73
  end
74
74
  end
75
75
 
76
- def get_column_value_from_id(id, column, model)
77
- return id if column == 'id'
78
- model ||= cacher_at(id).peek_self if has_cacher?
79
- return model.send(column) if model
80
- return where(id: id).limit(1).pluck(column).first
81
- end
82
-
83
76
  @@column_value_cache = ActiveModelCachers::ColumnValueCache.new
84
77
  def define_callback_for_cleaning_cache(class_name, column, foreign_key, on: nil, &clean)
85
78
  ActiveSupport::Dependencies.onload(class_name) do
@@ -57,7 +57,8 @@ module ActiveModelCachers
57
57
  def raw_to_cache_data(raw)
58
58
  return NilObject if raw == nil
59
59
  return FalseObject if raw == false
60
- return raw
60
+ clean_ar_cache(raw.is_a?(Array) ? raw : [raw])
61
+ return raw_without_singleton_methods(raw)
61
62
  end
62
63
 
63
64
  def cache_to_raw_data(cached_data)
@@ -75,5 +76,19 @@ module ActiveModelCachers
75
76
  raw_to_cache_data(get_without_cache(binding))
76
77
  end
77
78
  end
79
+
80
+ def clean_ar_cache(models)
81
+ return if not models.first.is_a?(::ActiveRecord::Base)
82
+ models.each_with_index do |model, index|
83
+ model.send(:clear_aggregation_cache)
84
+ model.send(:clear_association_cache)
85
+ end
86
+ end
87
+
88
+ def raw_without_singleton_methods(raw)
89
+ return raw if raw.singleton_methods.empty?
90
+ return raw.class.find_by(id: raw.id) if raw.is_a?(::ActiveRecord::Base) # cannot marshal singleton, so load a new record instead.
91
+ return raw # not sure what to do with other cases
92
+ end
78
93
  end
79
94
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveModelCachers
3
- VERSION = "2.0.2"
3
+ VERSION = "2.0.3"
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.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
@@ -116,6 +116,7 @@ files:
116
116
  - gemfiles/4.2.gemfile
117
117
  - gemfiles/5.0.gemfile
118
118
  - gemfiles/5.1.gemfile
119
+ - gemfiles/5.2.gemfile
119
120
  - lib/active_model_cachers.rb
120
121
  - lib/active_model_cachers/active_record/attr_model.rb
121
122
  - lib/active_model_cachers/active_record/cacher.rb
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project:
154
- rubygems_version: 2.6.13
155
+ rubygems_version: 2.7.6
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: Let you cache whatever you want with ease by providing cachers to active