activerecord-cached_at 2.0.12 → 6.0.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
- SHA1:
3
- metadata.gz: 8176a13705e644ac3fa27b5690c68ec7c4d43f46
4
- data.tar.gz: e022fb6d8d7c6da36aa819fb3809a05a86c2f06d
2
+ SHA256:
3
+ metadata.gz: d0d9e3d63dbd18d8baab8017ad304e44f55b73ebe42060e0723438b252dc4cfe
4
+ data.tar.gz: 1c6cbb926a39f8c2cabe19a44d918e063df2f6278d443ea3d13ffae37b28e608
5
5
  SHA512:
6
- metadata.gz: 9b0cc35ece0124d0027967d615b1665f58ca15451aa148e87f154455e4c599bedbd71dbc951b174ae12271cc9aece81a390a9124765608d66af1782edbfcdde6
7
- data.tar.gz: 9131194d596d3fb06f205068c4afdcb6731dbd5d83902c0f5980c4bb07d875bf378332b1bd2659ed010c08a8394040162d9aa31db7e73c23e211fb980f13ce62
6
+ metadata.gz: bfafa9a17b95d329a28b0b7b3cc2c570b5cb206b9e9ab51a653f263b971fa59e5d56b4ecc87db02c1a0a526e98ff2ef3012ccc49b31b73da3f7c65cec9d7fc5b
7
+ data.tar.gz: 1311efa1ca1b808d636739c417ceb5561976e9d6565096ba871a51bed9e2faa40110de75a000c48d93e51e63e3022f523cdfd7fb05e956e9a82e734c81c704fa
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
- # ActiveRecord - CachedAt
1
+ # ActiveRecord - CachedAt [![Travis CI](https://travis-ci.org/malomalo/activerecord-cached_at.svg?branch=master)](https://travis-ci.org/malomalo/activerecord-cached_at)
2
2
 
3
3
  This gem causes ActiveRecord to update a `cached_at` column if present, like the
4
4
  `updated_at` column.
5
5
 
6
6
  When calculating a `cache_key` for a model it will also consider the `cached_at`
7
- column to determin the key of a model.
7
+ column to determine the key of a model.
8
8
 
9
9
  Any `ActiveRecord::Migration` that calls `timestamps` will include a `cached_at`
10
10
  column.
11
11
 
12
- TODO: Document about relationship caches
12
+ Call to [`ActiveRecord::Persistence::touch`](https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-touch)
13
+ will also touch the `cached_at` column.
13
14
 
14
15
  ## Installation
15
16
 
@@ -22,12 +23,94 @@ aren't updating the models you can just require the helpers:
22
23
 
23
24
  gem 'activerecord-cached_at', require: 'cached_at/helpers'
24
25
 
26
+ ## Configuration
25
27
 
28
+ By default updates to the `cached_at`, `updated_at`, and `created_at` columns
29
+ will not trigger and update to the `cached_at` column. You can add aditional
30
+ fields to ignore:
31
+
32
+ ```ruby
33
+ class User
34
+ cached_at ignore: :my_column
35
+ end
36
+
37
+ class Photo
38
+ cached_at ignore: :column_a, :column_b
39
+ end
40
+ ```
41
+ ## Relationship Cache Keys
42
+
43
+ CachedAt also allows you to keep cache keys for relationships. This allows you
44
+ to use the record to determine if a cache is valid for a relationship instead
45
+ of doing another database query.
46
+
47
+ For example:
48
+
49
+ ```ruby
50
+ class User < ActiveRecord::Base
51
+ has_many :photos
52
+ end
53
+
54
+ class Photo
55
+ belongs_to :user, cached_at: true
56
+ end
57
+
58
+ bob_ross = User.create(name: 'Bob Ross')
59
+ # => INSERT INTO "users"
60
+ # ("name", "cached_at", "updated_at_", "created_at")
61
+ # VALUES
62
+ # ("Bob Ross", "2020-07-19 20:22:03", "2020-07-19 20:22:03", "2020-07-19 20:22:03")
63
+
64
+ photo = Photo.create(user: bob_ross, file: ...)
65
+ # =>INSERT INTO "photos" ("user_id", "cached_at", "updated_at_", "created_at") VALUES (1, "Bob Ross", "2020-07-19 20:22:04", "2020-07-19 20:22:04", "2020-07-19 20:22:04")
66
+ # => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:04" WHERE "users"."id" = 1
67
+
68
+ photo.update(file: ...)
69
+ # =>UPDATE "photos" (..., "cached_at", "updated_at_") VALUES (..., "2020-07-19 20:22:05", "2020-07-19 20:22:05", "2020-07-19 20:22:05")
70
+ # => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:05" WHERE "users"."id" = 1
71
+
72
+ photo.update(user: not_bob_ross)
73
+ # =>UPDATE "photos" ("user_id", "cached_at", "updated_at_") VALUES (2, "2020-07-19 20:22:06", "2020-07-19 20:22:06", "2020-07-19 20:22:06")
74
+ # => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:06" WHERE "users"."id" IN (1, 2)
75
+
76
+ photo.destroy
77
+ # => UPDATE "users" SET "photos_cached_at" = "2020-07-19 20:22:07" WHERE "users"."id" = 2
78
+ # => DELETE FROM "users" WHERE WHERE "users"."id" = 2
79
+ ```
80
+
81
+ # Usage
82
+
83
+ `cached_at` will automatically be used for determining the cache key in Rails.
84
+
85
+ However if you need to calculate the cache key based on relationship cache keys
86
+ you will need to manually compute the cache key. Examples are below:
87
+
88
+ The cache key here is the maxium of the following keys: `cached_at`,
89
+ `listings_cached_at`, and `photos_cached_at`
90
+
91
+ ```erb
92
+ <%= render partial: 'row', collection: @properties, as: :property, cached: Proc.new { |item|
93
+ [item.cache_key_with_version(:listings, :photos), current_account.id ]
94
+ } %>
95
+
96
+ <% cache @property.cache_key_with_version(:listings, :photos) do %>
97
+ <b>All the info on this property</b>
98
+ <%= @property.name %>
99
+ <% @property.listings.each do |listing| %>
100
+ <%= listing.info %>
101
+ <% end %>
102
+ <% @property.photos.each do |photo| %>
103
+ <%= image_tag(photo.url) %>
104
+ <% end %>
105
+ <% end %>
106
+
107
+ ```
26
108
  ## TODO:
27
109
 
28
- Add a `cache_key` method to the Model class that gets `MAX(cached_at)`
110
+ * Document going more than one level with cached_at keys
29
111
 
112
+ * Add a `cache_key` method to the Model class that gets `MAX(cached_at)`
30
113
 
114
+ * change option to cache: true
31
115
 
32
- change option to cache: true
33
- add cache_association helper
116
+ * add cache_association helper
@@ -2,6 +2,7 @@ module CachedAt
2
2
  module AssociationExtension
3
3
 
4
4
  def self.build(model, reflection)
5
+ return unless reflection.options[:cached_at]
5
6
  end
6
7
 
7
8
  def self.valid_options
@@ -11,4 +12,4 @@ module CachedAt
11
12
  end
12
13
  end
13
14
 
14
- ActiveRecord::Associations::Builder::Association.extensions << CachedAt::AssociationExtension
15
+ ActiveRecord::Associations::Builder::Association.extensions << CachedAt::AssociationExtension
@@ -1,9 +1,5 @@
1
1
  module CachedAt
2
2
  module Association
3
-
4
- def initialize(owner, reflection)
5
- super
6
- end
7
3
 
8
4
  def traverse_relationships(klass, relationships, query, cache_column, timestamp)
9
5
  if relationships.is_a?(Symbol)
@@ -45,7 +41,7 @@ module CachedAt
45
41
 
46
42
  source_assoc = owner.association(r.source_reflection_name.to_sym)
47
43
  if source_assoc.loaded?
48
- source_assoc.target.raw_write_attribute(cache_column, timestamp)
44
+ source_assoc.target.send(:write_attribute_without_type_cast, cache_column, timestamp)
49
45
  end
50
46
  query = r.klass.where(r.association_primary_key => owner.send(r.foreign_key))
51
47
  query.update_all({ cache_column => timestamp })
@@ -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,14 +38,14 @@ 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)
45
45
  end
46
46
 
47
47
  if loaded? && target
48
- target.raw_write_attribute(cache_column, timestamp)
48
+ target.send(:write_attribute_without_type_cast, cache_column, timestamp)
49
49
  end
50
50
  end
51
51
 
@@ -54,7 +54,7 @@ module CachedAt
54
54
  timestamp = Time.now
55
55
  cache_column = "#{options[:inverse_of]}_cached_at"
56
56
  if loaded? && target
57
- target.raw_write_attribute(cache_column, timestamp)
57
+ target.send(:write_attribute_without_type_cast, cache_column, timestamp)
58
58
  end
59
59
  end
60
60
 
@@ -10,11 +10,11 @@ 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?
17
- target.each { |r| r.raw_write_attribute(cache_column, timestamp) }
17
+ target.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) }
18
18
  end
19
19
 
20
20
  if method != :destroy
@@ -40,7 +40,7 @@ module CachedAt
40
40
 
41
41
  cache_column = "#{reflection.inverse_of.name}_cached_at"
42
42
 
43
- records.each { |r| r.raw_write_attribute(cache_column, timestamp) unless r.destroyed? }
43
+ records.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) unless r.destroyed? }
44
44
 
45
45
  query = klass.where({ klass.primary_key => records.map(&:id) })
46
46
  query.update_all({ cache_column => timestamp })
@@ -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)
@@ -15,10 +15,10 @@ module CachedAt
15
15
 
16
16
  query = nil
17
17
  if loaded?
18
- target.each { |r| r.raw_write_attribute(cache_column, timestamp) }
18
+ target.each { |r| r.send(:write_attribute_without_type_cast, 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)
@@ -35,7 +35,7 @@ module CachedAt
35
35
  #TODO: test with new record (fails in mls)
36
36
  if !owner.new_record? && using_reflection.inverse_of && using_reflection.inverse_of.options[:cached_at]
37
37
  cache_column = "#{using_reflection.name}_cached_at"
38
- owner.raw_write_attribute(cache_column, timestamp)
38
+ owner.send(:write_attribute_without_type_cast, cache_column, timestamp)
39
39
  owner.update_columns(cache_column => timestamp)
40
40
  end
41
41
  end
@@ -50,7 +50,7 @@ module CachedAt
50
50
  end
51
51
 
52
52
  cache_column = "#{using_reflection.inverse_of.name}_cached_at"
53
- records.each { |r| r.raw_write_attribute(cache_column, timestamp) }
53
+ records.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) }
54
54
  query = klass.where(klass.primary_key => records.map(&:id))
55
55
  query.update_all({ cache_column => timestamp })
56
56
  traverse_relationships(klass, using_reflection.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
  case options[:dependent]
@@ -24,7 +24,7 @@ module CachedAt
24
24
  end
25
25
 
26
26
  if loaded? && target
27
- target.raw_write_attribute(cache_column, timestamp)
27
+ target.send(:write_attribute_without_type_cast, cache_column, timestamp)
28
28
  end
29
29
  end
30
30
 
@@ -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'))
@@ -12,27 +13,42 @@ module CachedAt
12
13
  extend ActiveSupport::Concern
13
14
 
14
15
  included do
16
+ class_attribute :cached_at_settings, default: {ignore: ['cached_at', 'updated_at', 'created_at']}
17
+ before_save :set_cached_at
15
18
  before_save :update_belongs_to_cached_at_keys
16
19
  before_destroy { update_relations_cached_at(method: :destroy) }
17
20
 
18
21
  after_touch { update_relations_cached_at_from_cached_at(method: :touch) }
19
- after_save :update_relations_cached_at_from_cached_at
22
+ after_save :update_relations_cached_at_from_cached_at
23
+ end
24
+
25
+ class_methods do
26
+ def cached_at(ignore: [])
27
+ ignore = [ignore] if !ignore.is_a?(Array)
28
+ self.cached_at_settings[:ignore].push(*ignore.map(&:to_s))
29
+ end
30
+ end
31
+
32
+ def touch(*names, time: nil)
33
+ names.push('cached_at')
34
+ super(*names, time: time)
20
35
  end
21
36
 
22
37
  private
23
38
 
24
39
  def update_relations_cached_at_from_cached_at(method: nil)
25
- update_relations_cached_at({
40
+ update_relations_cached_at(
26
41
  timestamp: (self.class.column_names.include?('cached_at') ? cached_at : nil),
27
42
  method: method
28
- })
43
+ )
29
44
  end
30
45
 
31
46
  def update_relations_cached_at(timestamp: nil, method: nil)
32
47
  method = instance_variable_defined?(:@new_record_before_save) && @new_record_before_save ? :create : :update if method.nil?
33
48
 
34
- return if method == :create && changes.empty?
35
- return if method == :update && changes.empty?
49
+ diff = saved_changes.transform_values(&:first)
50
+ return if method == :create && diff.empty?
51
+ return if method == :update && diff.empty?
36
52
 
37
53
  timestamp ||= current_time_from_proper_timezone
38
54
 
@@ -47,22 +63,30 @@ module CachedAt
47
63
  end
48
64
  end
49
65
 
66
+ def set_cached_at
67
+ return if !self.class.column_names.include?('cached_at')
68
+ diff = changes.transform_values(&:first)
69
+ return if diff.keys.all? { |k| cached_at_settings[:ignore].include?(k) }
70
+
71
+ self.cached_at = current_time_from_proper_timezone
72
+ end
73
+
50
74
  def update_belongs_to_cached_at_keys
51
75
  self.class.reflect_on_all_associations.each do |reflection|
52
76
  next unless reflection.is_a?(ActiveRecord::Reflection::BelongsToReflection)
53
77
  cache_column = "#{reflection.name}_cached_at"
54
78
 
55
79
  if self.attribute_names.include?(cache_column)
56
- if self.changes.has_key?(reflection.foreign_key) && self.changes[reflection.foreign_key][1].nil?
80
+ if self.changes_to_save.has_key?(reflection.foreign_key) && self.changes_to_save[reflection.foreign_key][1].nil?
57
81
  self.assign_attributes({ cache_column => current_time_from_proper_timezone })
58
- elsif (self.changes[reflection.foreign_key] || self.new_record? || (self.association(reflection.name).loaded? && self.send(reflection.name) && self.send(reflection.name).id.nil?)) && self.send(reflection.name).try(:cached_at)
82
+ elsif (self.changes_to_save[reflection.foreign_key] || self.new_record? || (self.association(reflection.name).loaded? && self.send(reflection.name) && self.send(reflection.name).id.nil?)) && self.send(reflection.name).try(:cached_at)
59
83
  self.assign_attributes({ cache_column => self.send(reflection.name).cached_at })
60
84
  end
61
85
  end
62
86
 
63
87
  end
64
88
  end
65
-
89
+
66
90
  end
67
91
  end
68
92
 
@@ -2,14 +2,12 @@ module ActiveRecord
2
2
  module ConnectionAdapters #:nodoc:
3
3
 
4
4
  class TableDefinition
5
- def timestamps(*args)
6
- options = args.extract_options!
7
-
5
+ def timestamps(**options)
8
6
  options[:null] = false if options[:null].nil?
9
7
 
10
8
  column(:created_at, :datetime, options)
11
9
  column(:updated_at, :datetime, options)
12
- column(:cached_at, :datetime, options)
10
+ column(:cached_at, :datetime, options)
13
11
  end
14
12
  end
15
13
 
@@ -7,7 +7,7 @@ module ActiveRecord
7
7
 
8
8
  add_column table_name, :created_at, :datetime, options
9
9
  add_column table_name, :updated_at, :datetime, options
10
- add_column table_name, :cached_at, :datetime, options
10
+ add_column table_name, :cached_at, :datetime, options
11
11
  end
12
12
 
13
13
  def remove_timestamps(table_name, options = {})
@@ -29,16 +29,40 @@ module CachedAt
29
29
 
30
30
  end
31
31
 
32
- def cache_key(includes = nil)
32
+ def cache_key(*includes)
33
33
  if includes.nil? || includes.empty?
34
- super
34
+ if cache_versioning
35
+ "#{model_name.cache_key}/#{id}"
36
+ else
37
+ "#{model_name.cache_key}/#{id}@#{cache_version}"
38
+ end
39
+ else
40
+ digest = Digest::MD5.hexdigest(paramaterize_cache_includes(includes))
41
+ if cache_versioning
42
+ "#{model_name.cache_key}/#{id}+#{digest}"
43
+ else
44
+ "#{model_name.cache_key}/#{id}+#{digest}@#{cache_version(includes)}"
45
+ end
46
+ end
47
+ end
48
+
49
+ def cache_key_with_version(*includes)
50
+ if version = cache_version(*includes)
51
+ "#{cache_key(*includes)}-#{version}"
52
+ else
53
+ cache_key(*includes)
54
+ end
55
+ end
56
+
57
+ def cache_version(*includes)
58
+ timestamp = if includes.empty?
59
+ try(:cached_at) || try(:cached_at)
35
60
  else
36
61
  timestamp_keys = ['cached_at'] + self.class.cached_at_columns_for_includes(includes)
37
- timestamp = max_updated_column_timestamp(timestamp_keys).utc.to_s(cache_timestamp_format)
38
- digest ||= Digest::MD5.new()
39
- digest << paramaterize_cache_includes(includes)
40
- "#{model_name.cache_key}/#{id}+#{digest.hexdigest}@#{timestamp}"
62
+ timestamp = timestamp_keys.map { |attr| self[attr]&.to_time }.compact.max
41
63
  end
64
+
65
+ timestamp.utc.to_s(:usec)
42
66
  end
43
67
 
44
68
  # TODO
@@ -84,4 +108,4 @@ module CachedAt
84
108
  end
85
109
  end
86
110
 
87
- ActiveRecord::Base.include(CachedAt::Base::Helpers)
111
+ ActiveRecord::Base.include(CachedAt::Base::Helpers)
@@ -1,30 +1,42 @@
1
1
  module CachedAt
2
2
  module AbstractReflection
3
3
 
4
- def through_relationship_endpoints
5
- return @through_relationship_endpoints if instance_variable_defined?(:@through_relationship_endpoints)
6
-
7
- @through_relationship_endpoints = []
8
- active_record.reflections.each do |name, r|
9
- next if r == self
10
- begin
11
- if r.polymorphic?
12
- # TODO
13
- else
14
- r.klass.reflections.each do |name2, r2|
15
- if r2.options[:cached_at] && r2.options[:through] && r2.options[:through] == r.inverse_of&.name
16
- @through_relationship_endpoints << r2
17
- end
18
- end
19
- end
20
- rescue NameError
21
- end
4
+ def cache_through_relationship_endpoints
5
+ if defined?(Rails)
6
+ Rails.application.config.cache_classes
7
+ else
8
+ true
22
9
  end
10
+ end
23
11
 
12
+ def through_relationship_endpoints
13
+ return @through_relationship_endpoints if instance_variable_defined?(:@through_relationship_endpoints) && cache_through_relationship_endpoints
14
+
15
+ @through_relationship_endpoints = if defined?(Rails)
16
+ Rails.application.reloader.wrap { calculate_through_relationship_endpoints }
17
+ else
18
+ calculate_through_relationship_endpoints
19
+ end
20
+
24
21
  @through_relationship_endpoints
25
22
  end
26
23
 
24
+ def calculate_through_relationship_endpoints
25
+ endpoints = []
26
+
27
+ if self.polymorphic?
28
+ else
29
+ self.klass._reflections.each do |name, r|
30
+ if r.options[:cached_at] && r.options[:through] && r.options[:through] == self.inverse_of&.name
31
+ endpoints << r
32
+ end
33
+ end
34
+ end
35
+
36
+ endpoints
37
+ end
38
+
27
39
  end
28
40
  end
29
41
 
30
- ActiveRecord::Reflection::AbstractReflection.include(CachedAt::AbstractReflection)
42
+ ActiveRecord::Reflection::AbstractReflection.include(CachedAt::AbstractReflection)
@@ -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']
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.12'
2
+ VERSION = '6.0.0'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cached_at
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.12
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0
19
+ version: 5.2.1
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.2.1
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
@@ -152,7 +153,7 @@ homepage: https://github.com/malomalo/activerecord-cached_at
152
153
  licenses:
153
154
  - MIT
154
155
  metadata: {}
155
- post_install_message:
156
+ post_install_message:
156
157
  rdoc_options:
157
158
  - "--main"
158
159
  - README.md
@@ -169,9 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  - !ruby/object:Gem::Version
170
171
  version: '0'
171
172
  requirements: []
172
- rubyforge_project:
173
- rubygems_version: 2.5.1
174
- signing_key:
173
+ rubygems_version: 3.1.2
174
+ signing_key:
175
175
  specification_version: 4
176
176
  summary: Allows ActiveRecord and Rails to use a `cached_at` column for the `cache_key`
177
177
  if available