activerecord-cached_at 2.0.12 → 2.0.13

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
2
  SHA1:
3
- metadata.gz: 8176a13705e644ac3fa27b5690c68ec7c4d43f46
4
- data.tar.gz: e022fb6d8d7c6da36aa819fb3809a05a86c2f06d
3
+ metadata.gz: c744adeef1d92b25ca053e9553e23d107317b0db
4
+ data.tar.gz: 07d579d29d299964580a6025509c756d01fddb3f
5
5
  SHA512:
6
- metadata.gz: 9b0cc35ece0124d0027967d615b1665f58ca15451aa148e87f154455e4c599bedbd71dbc951b174ae12271cc9aece81a390a9124765608d66af1782edbfcdde6
7
- data.tar.gz: 9131194d596d3fb06f205068c4afdcb6731dbd5d83902c0f5980c4bb07d875bf378332b1bd2659ed010c08a8394040162d9aa31db7e73c23e211fb980f13ce62
6
+ metadata.gz: 8b32156ffebc82c9fc2a75e1244edfafe76b51bee868eb8126de844220e4afe75c11415cd8d169b28c6138fb2b6aef4f87ee9d05e25a8f94936464756f3511cc
7
+ data.tar.gz: '0706495432358f4a0b816e93b0d9fd1b5bf284acd36cdd4fe71f9c9969fbec238a1ae69e92a07ae3db3c975ba53e9b6c3fc0596f9a0c6628d3d67e5495893d62'
@@ -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)
@@ -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,3 +1,3 @@
1
1
  module CachedAt
2
- VERSION = '2.0.12'
2
+ VERSION = '2.0.13'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  requirements: []
172
172
  rubyforge_project:
173
- rubygems_version: 2.5.1
173
+ rubygems_version: 2.5.2
174
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`