activerecord-cached_at 2.0.13 → 5.1.0

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
  SHA1:
3
- metadata.gz: c744adeef1d92b25ca053e9553e23d107317b0db
4
- data.tar.gz: 07d579d29d299964580a6025509c756d01fddb3f
3
+ metadata.gz: c9738b748326936b6c9ca40a335f3ff903ddbdb2
4
+ data.tar.gz: d2a4acd817f4f27deaa58984ab285946c711dbd8
5
5
  SHA512:
6
- metadata.gz: 8b32156ffebc82c9fc2a75e1244edfafe76b51bee868eb8126de844220e4afe75c11415cd8d169b28c6138fb2b6aef4f87ee9d05e25a8f94936464756f3511cc
7
- data.tar.gz: '0706495432358f4a0b816e93b0d9fd1b5bf284acd36cdd4fe71f9c9969fbec238a1ae69e92a07ae3db3c975ba53e9b6c3fc0596f9a0c6628d3d67e5495893d62'
6
+ metadata.gz: 0b16e4afd909f8091721348e23d54f2d71427bcb550016d77677574bb19a525c2f12cb8fbccb25b1de39d82604f954be5674ec7e99611bfb0e776c21398bdcb0
7
+ data.tar.gz: 49bc4f9883cd48034e0dcad03b8525e750dd59244e143946d3c33b4f88a54d19705183b69492dba045dee6dc9e4729ca9b144817603ce718f734a11b3b671f0e
@@ -13,8 +13,8 @@ module CachedAt
13
13
 
14
14
  cache_column = "#{options[:inverse_of]}_cached_at"
15
15
  if options[:polymorphic]
16
- oldtype = owner.send("#{reflection.foreign_type}_was")
17
- oldid = owner.send("#{reflection.foreign_key}_was")
16
+ oldtype = owner.send("#{reflection.foreign_type}_before_last_save")
17
+ oldid = owner.send("#{reflection.foreign_key}_before_last_save")
18
18
  newtype = owner.send(reflection.foreign_type)
19
19
  newid = owner.send(reflection.foreign_key)
20
20
  if !oldtype.nil? && oldtype == newtype
@@ -38,7 +38,7 @@ module CachedAt
38
38
  end
39
39
  end
40
40
  else
41
- ids = [owner.send(reflection.foreign_key), owner.send("#{reflection.foreign_key}_was")].compact.uniq
41
+ ids = [owner.send(reflection.foreign_key), owner.send("#{reflection.foreign_key}_before_last_save")].compact.uniq
42
42
  query = klass.where({ reflection.association_primary_key => ids })
43
43
  query.update_all({ cache_column => timestamp })
44
44
  traverse_relationships(klass, options[:cached_at], query, cache_column, timestamp)
@@ -10,7 +10,7 @@ module CachedAt
10
10
  end
11
11
 
12
12
  cache_column = "#{reflection.inverse_of.name}_cached_at"
13
- ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}_was")].compact.uniq
13
+ ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}_before_last_save")].compact.uniq
14
14
  query = klass.where({ reflection.foreign_key => ids })
15
15
 
16
16
  if loaded?
@@ -0,0 +1,10 @@
1
+ module CachedAt
2
+ module CollectionProxy
3
+ def delete(*records)
4
+ @association.touch_records_cached_at(records, Time.now) unless @association.owner.new_record?
5
+ super
6
+ end
7
+ end
8
+ end
9
+
10
+ ActiveRecord::Associations::CollectionProxy.prepend(CachedAt::CollectionProxy)
@@ -18,7 +18,7 @@ module CachedAt
18
18
  target.each { |r| r.raw_write_attribute(cache_column, timestamp) }
19
19
  query = klass.where(klass.primary_key => target.map(&:id))
20
20
  else
21
- ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}_was")].compact.uniq
21
+ ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}_before_last_save")].compact.uniq
22
22
  arel_table = klass._reflections[using_reflection.inverse_of.options[:through].to_s].klass.arel_table
23
23
  query = klass.joins(using_reflection.inverse_of.options[:through])
24
24
  query = if using_reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
@@ -10,7 +10,7 @@ module CachedAt
10
10
  end
11
11
 
12
12
  cache_column = "#{reflection.inverse_of.name}_cached_at"
13
- ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}_was")].compact.uniq
13
+ ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}_before_last_save")].compact.uniq
14
14
  query = klass.where({ reflection.foreign_key => ids })
15
15
 
16
16
  case options[:dependent]
@@ -3,6 +3,7 @@ require File.expand_path(File.join(__FILE__, '../associations/association'))
3
3
  require File.expand_path(File.join(__FILE__, '../associations/has_one_association'))
4
4
  require File.expand_path(File.join(__FILE__, '../associations/belongs_to_association'))
5
5
  require File.expand_path(File.join(__FILE__, '../associations/collection_association'))
6
+ require File.expand_path(File.join(__FILE__, '../associations/collection_proxy'))
6
7
  require File.expand_path(File.join(__FILE__, '../associations/has_many_through_association'))
7
8
 
8
9
  require File.expand_path(File.join(__FILE__, '../reflections/abstract_reflection'))
@@ -31,8 +32,9 @@ module CachedAt
31
32
  def update_relations_cached_at(timestamp: nil, method: nil)
32
33
  method = instance_variable_defined?(:@new_record_before_save) && @new_record_before_save ? :create : :update if method.nil?
33
34
 
34
- return if method == :create && changes.empty?
35
- return if method == :update && changes.empty?
35
+ diff = saved_changes.transform_values(&:first)
36
+ return if method == :create && diff.empty?
37
+ return if method == :update && diff.empty?
36
38
 
37
39
  timestamp ||= current_time_from_proper_timezone
38
40
 
@@ -1,15 +1,22 @@
1
1
  module ActiveRecord
2
- module Timestamp
3
-
4
- private
2
+ module CachedAt
3
+ module Timestamp
4
+ extend ActiveSupport::Concern
5
+
6
+ class_methods do
7
+ private
5
8
 
6
- def timestamp_attributes_for_update
7
- [:updated_at, :cached_at]
8
- end
9
+ def timestamp_attributes_for_update
10
+ ['updated_at', 'cached_at']
11
+ end
12
+
13
+ def timestamp_attributes_for_create
14
+ ['created_at', 'udpated_at', 'cached_at'] + column_names.select{|c| c.end_with?('_cached_at') }
15
+ end
9
16
 
10
- def timestamp_attributes_for_create
11
- [:created_at, :udpated_at, :cached_at] + self.class.column_names.select{|c| c.end_with?('_cached_at') }.map(&:to_sym)
17
+ end
12
18
  end
13
-
14
19
  end
15
- end
20
+ end
21
+
22
+ ActiveRecord::Base.include(ActiveRecord::CachedAt::Timestamp)
@@ -1,3 +1,3 @@
1
1
  module CachedAt
2
- VERSION = '2.0.13'
2
+ VERSION = '5.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cached_at
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.13
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: 5.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.0
26
+ version: 5.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +139,7 @@ files:
139
139
  - lib/cached_at/associations/association.rb
140
140
  - lib/cached_at/associations/belongs_to_association.rb
141
141
  - lib/cached_at/associations/collection_association.rb
142
+ - lib/cached_at/associations/collection_proxy.rb
142
143
  - lib/cached_at/associations/has_many_through_association.rb
143
144
  - lib/cached_at/associations/has_one_association.rb
144
145
  - lib/cached_at/base.rb
@@ -170,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
171
  version: '0'
171
172
  requirements: []
172
173
  rubyforge_project:
173
- rubygems_version: 2.5.2
174
+ rubygems_version: 2.6.11
174
175
  signing_key:
175
176
  specification_version: 4
176
177
  summary: Allows ActiveRecord and Rails to use a `cached_at` column for the `cache_key`