activerecord-cached_at 6.1.0 → 7.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
  SHA256:
3
- metadata.gz: 89f6c8c10ca1cb627c057112961cb80ff26440026b723b5cf4240e4873089604
4
- data.tar.gz: 05374e1138987e67d9a0fb5866278f1d495168799859ccb8cc77e4bc8dc8b724
3
+ metadata.gz: a06a10c91336f7e319a46263bb7f3860c3c21e861c9e50c6263fc414a1e6cfbb
4
+ data.tar.gz: 7c1e74bb4eb06fa0a1bcc70f8eade6b87cf835b3f7d72da86192edd65b2bd2ed
5
5
  SHA512:
6
- metadata.gz: 2053953fe7212f64ee1d03ed6956f409f25ae3c53666c25acd7224ecefa3e8ed0b1d2daf99317087d7c7fed0ea846a10eceec4de9776c31c530f31bc518b54ab
7
- data.tar.gz: fbeed1272d1d6a5961733ec128516a5b1dc9f093061775c24ba1c14c30bf28f8730436542d8ca45de738a41d957332fd5daf133d74d54c37b9f6f9db137c7eff
6
+ metadata.gz: 6a66a1cb25a04423178c5a2d5ca1e818f3681756c613b7fc0ad5356b7760db762ac64377c4ac2b14f5cbee7fe2562686e9801812e792495de0682b81fffa6f37
7
+ data.tar.gz: 234132056063c4e157890bbad45728b29f0ffd899a4170f53bc8c2563206cda5c7abc697da532fbfb738fc147d58e56ae15ca36584078a9775987b37fe991cba
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ActiveRecord - CachedAt [![Travis CI](https://travis-ci.org/malomalo/activerecord-cached_at.svg?branch=master)](https://travis-ci.org/malomalo/activerecord-cached_at)
1
+ # ActiveRecord - CachedAt
2
2
 
3
3
  This gem causes ActiveRecord to update a `cached_at` column if present, like the
4
4
  `updated_at` column.
@@ -2,6 +2,11 @@ module ActiveRecord
2
2
  module ConnectionAdapters #:nodoc:
3
3
 
4
4
  class TableDefinition
5
+
6
+ def internal_table?
7
+ @name == "#{ActiveRecord::Base.table_name_prefix}#{ActiveRecord::Base.internal_metadata_table_name}#{ActiveRecord::Base.table_name_suffix}"
8
+ end
9
+
5
10
  def timestamps(**options)
6
11
  options[:null] = false if options[:null].nil?
7
12
 
@@ -11,7 +16,7 @@ module ActiveRecord
11
16
 
12
17
  column(:created_at, :datetime, **options)
13
18
  column(:updated_at, :datetime, **options)
14
- column(:cached_at, :datetime, **options)
19
+ column(:cached_at, :datetime, **options) if !internal_table?
15
20
  end
16
21
  end
17
22
 
@@ -2,22 +2,8 @@ module ActiveRecord
2
2
  module ConnectionAdapters #:nodoc:
3
3
 
4
4
  module SchemaStatements
5
- def add_timestamps(table_name, **options)
6
- options[:null] = false if options[:null].nil?
7
-
8
- if !options.key?(:precision) && supports_datetime_with_precision?
9
- options[:precision] = 6
10
- end
11
-
12
- add_column table_name, :created_at, :datetime, **options
13
- add_column table_name, :updated_at, :datetime, **options
14
- add_column table_name, :cached_at, :datetime, **options
15
- end
16
-
17
5
  def remove_timestamps(table_name, **options)
18
- remove_column table_name, :updated_at
19
- remove_column table_name, :created_at
20
- remove_column table_name, :cached_at
6
+ remove_columns table_name, :updated_at, :created_at, :cached_at
21
7
  end
22
8
 
23
9
  def add_timestamps_for_alter(table_name, **options)
@@ -33,12 +19,26 @@ module ActiveRecord
33
19
  add_column_for_alter(table_name, :cached_at, :datetime, **options)
34
20
  ]
35
21
  end
22
+ end
36
23
 
37
- def remove_timestamps_for_alter(table_name, **options)
38
- remove_columns_for_alter(table_name, :updated_at, :created_at, :cached_at)
39
- end
24
+ end
25
+ end
40
26
 
41
- end
42
27
 
28
+ ActiveSupport.on_load(:active_record_sqlite3adapter) do
29
+ class ActiveRecord::ConnectionAdapters::SQLite3Adapter
30
+ def add_timestamps(table_name, **options)
31
+ options[:null] = false if options[:null].nil?
32
+
33
+ if !options.key?(:precision)
34
+ options[:precision] = 6
35
+ end
36
+
37
+ alter_table(table_name) do |definition|
38
+ definition.column :created_at, :datetime, **options
39
+ definition.column :updated_at, :datetime, **options
40
+ definition.column :cached_at, :datetime, **options
41
+ end
42
+ end
43
43
  end
44
44
  end
@@ -41,7 +41,8 @@ module CachedAt
41
41
 
42
42
  source_assoc = owner.association(r.source_reflection_name.to_sym)
43
43
  if source_assoc.loaded?
44
- source_assoc.target.send(:write_attribute_without_type_cast, cache_column, timestamp)
44
+ source_assoc.target.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
45
+ source_assoc.target.send(:clear_attribute_change, cache_column)
45
46
  end
46
47
  query = r.klass.where(r.association_primary_key => owner.send(r.foreign_key))
47
48
  query.update_all({ cache_column => timestamp })
@@ -45,7 +45,8 @@ module CachedAt
45
45
  end
46
46
 
47
47
  if loaded? && target
48
- target.send(:write_attribute_without_type_cast, cache_column, timestamp)
48
+ target.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
49
+ target.send(:clear_attribute_change, cache_column)
49
50
  end
50
51
  end
51
52
 
@@ -54,7 +55,8 @@ module CachedAt
54
55
  timestamp = Time.now
55
56
  cache_column = "#{options[:inverse_of]}_cached_at"
56
57
  if loaded? && target
57
- target.send(:write_attribute_without_type_cast, cache_column, timestamp)
58
+ target.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
59
+ target.send(:clear_attribute_change, cache_column)
58
60
  end
59
61
  end
60
62
 
@@ -15,7 +15,8 @@ module CachedAt
15
15
 
16
16
  if loaded?
17
17
  target.each do |record|
18
- record.send(:write_attribute_without_type_cast, cache_column, timestamp)
18
+ record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
19
+ record.send(:clear_attribute_change, cache_column)
19
20
  end
20
21
  end
21
22
 
@@ -42,7 +43,12 @@ module CachedAt
42
43
 
43
44
  cache_column = "#{reflection.inverse_of.name}_cached_at"
44
45
 
45
- records.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) unless r.destroyed? }
46
+ records.each do |record|
47
+ next if record.destroyed?
48
+
49
+ record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
50
+ record.send(:clear_attribute_change, cache_column)
51
+ end
46
52
 
47
53
  query = klass.where({ klass.primary_key => records.map(&:id) })
48
54
  query.update_all({ cache_column => timestamp })
@@ -15,7 +15,10 @@ module CachedAt
15
15
 
16
16
  query = nil
17
17
  if loaded?
18
- target.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) }
18
+ target.each do |record|
19
+ record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
20
+ record.send(:clear_attribute_change, cache_column)
21
+ end
19
22
  query = klass.where(klass.primary_key => target.map(&:id))
20
23
  else
21
24
  ids = [owner.send(using_reflection.association_primary_key), owner.send("#{using_reflection.association_primary_key}_before_last_save")].compact.uniq
@@ -35,7 +38,8 @@ module CachedAt
35
38
  #TODO: test with new record (fails in mls)
36
39
  if !owner.new_record? && using_reflection.inverse_of && using_reflection.inverse_of.options[:cached_at]
37
40
  cache_column = "#{using_reflection.name}_cached_at"
38
- owner.send(:write_attribute_without_type_cast, cache_column, timestamp)
41
+ owner.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
42
+ owner.send(:clear_attribute_change, cache_column)
39
43
  owner.update_columns(cache_column => timestamp)
40
44
  end
41
45
  end
@@ -50,7 +54,10 @@ module CachedAt
50
54
  end
51
55
 
52
56
  cache_column = "#{using_reflection.inverse_of.name}_cached_at"
53
- records.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) }
57
+ records.each do |record|
58
+ record.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
59
+ record.send(:clear_attribute_change, cache_column)
60
+ end
54
61
  query = klass.where(klass.primary_key => records.map(&:id))
55
62
  query.update_all({ cache_column => timestamp })
56
63
  traverse_relationships(klass, using_reflection.options[:cached_at], query, cache_column, timestamp)
@@ -24,7 +24,8 @@ module CachedAt
24
24
  end
25
25
 
26
26
  if loaded? && target
27
- target.send(:write_attribute_without_type_cast, cache_column, timestamp)
27
+ target.instance_variable_get(:@attributes).write_cast_value(cache_column, timestamp)
28
+ target.send(:clear_attribute_change, cache_column)
28
29
  end
29
30
  end
30
31
 
@@ -62,7 +62,7 @@ module CachedAt
62
62
  timestamp = timestamp_keys.map { |attr| self[attr]&.to_time }.compact.max
63
63
  end
64
64
 
65
- timestamp.utc.to_s(:usec)
65
+ timestamp.utc.to_fs(:usec)
66
66
  end
67
67
 
68
68
  # TODO
@@ -7,7 +7,7 @@ module ActiveRecord
7
7
  private
8
8
 
9
9
  def timestamp_attributes_for_update
10
- ["updated_at", "updated_on", 'cached_at'].map! { |name| attribute_aliases[name] || name }
10
+ ["updated_at", "updated_on"].map! { |name| attribute_aliases[name] || name }
11
11
  end
12
12
 
13
13
  def timestamp_attributes_for_create
@@ -1,3 +1,3 @@
1
1
  module CachedAt
2
- VERSION = '6.1.0'
2
+ VERSION = '7.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: 6.1.0
4
+ version: 7.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: 2021-01-14 00:00:00.000000000 Z
11
+ date: 2023-12-05 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: 6.1.0
19
+ version: 7.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: 6.1.0
26
+ version: 7.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: sqlite3
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -168,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
182
  - !ruby/object:Gem::Version
169
183
  version: '0'
170
184
  requirements: []
171
- rubygems_version: 3.2.3
185
+ rubygems_version: 3.4.13
172
186
  signing_key:
173
187
  specification_version: 4
174
188
  summary: Allows ActiveRecord and Rails to use a `cached_at` column for the `cache_key`