goldiloader 3.0.3 → 4.0.1

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: 5f23e35eaad8987983cf1c95ec9c99e281e23715
4
- data.tar.gz: 9882b6e39452af1d0a9d55b28b7d1d40e3e3513a
2
+ SHA256:
3
+ metadata.gz: 3da0240495233f97f9762b4c81249b24fc6b9fb39e46801243e865ae2ed4d50d
4
+ data.tar.gz: d5bc7704557c4a9cdaf4e8d8e31d7d066444a964faf31812ce34117f845ccbeb
5
5
  SHA512:
6
- metadata.gz: 22065fba51aa33fbc113ddc113a84d998de8b5915108c0dd54a878b182684155b957be4aa86bec6971010ff6f930a94116e4ebc4ff3490e6c0257975e0e26272
7
- data.tar.gz: 03244b1b7fc590389d9a89a0a5f26376c0198b1e0ce68e5605e5e254ad116e203ae88573da24ca671ed2b5bb44fe0d58cc19f9509a754c462fa9d0e9e2c36129
6
+ metadata.gz: 73ab77e3c22b3e80dc903079dfe65245fceae13ab8b4fa1870705df1d1302eac82982523fad9cf7b9c2f4576022894ff16c8cd83b72d966ede5cd88ffb2b56d0
7
+ data.tar.gz: 402c5bfe96112e1a697af866205c3a16cb85966566adcac722deefc4ce4d487b4df10e335d1ce057cb2ddcf5ce4c8d490998c46b3e20feca4d98f334f2719534
@@ -47,21 +47,12 @@ module Goldiloader
47
47
  end
48
48
 
49
49
  def auto_include_value
50
- # Note: Don't use get_value because that doesn't work properly with defaulting boolean values
51
50
  @values.fetch(:auto_include, true)
52
51
  end
53
52
 
54
53
  def auto_include_value=(value)
55
- if Goldiloader::Compatibility.rails_4?
56
- raise ::ActiveRecord::Relation::ImmutableRelation if @loaded
57
- check_cached_relation
58
- @values[:auto_include] = value
59
- elsif Goldiloader::Compatibility.rails_5_0?
60
- assert_mutability!
61
- @values[:auto_include] = value
62
- else
63
- set_value(:auto_include, value)
64
- end
54
+ assert_mutability!
55
+ @values[:auto_include] = value
65
56
  end
66
57
  end
67
58
  ::ActiveRecord::Relation.prepend(::Goldiloader::RelationPatch)
@@ -77,29 +68,26 @@ module Goldiloader
77
68
  ActiveRecord::Relation::Merger.prepend(::Goldiloader::MergerPatch)
78
69
 
79
70
  module AssociationReflectionPatch
80
- def eager_loadable?
81
- return @eager_loadable if instance_variable_defined?(:@eager_loadable)
82
-
83
- @eager_loadable = if scope.nil?
84
- # Associations without any scoping options are eager loadable
85
- true
86
- elsif scope.arity > 0
87
- # The scope will be evaluated for every model instance so it can't
88
- # be eager loaded
89
- false
90
- else
91
- scope_info = if Goldiloader::Compatibility.rails_4?
92
- Goldiloader::ScopeInfo.new(klass.unscoped.instance_exec(&scope) || klass.unscoped)
93
- else
94
- Goldiloader::ScopeInfo.new(scope_for(klass.unscoped))
95
- end
96
- scope_info.auto_include? &&
97
- !scope_info.limit? &&
98
- !scope_info.offset? &&
99
- (!has_one? || !scope_info.order?) &&
100
- (::Goldiloader::Compatibility.group_eager_loadable? || !scope_info.group?) &&
101
- (::Goldiloader::Compatibility.from_eager_loadable? || !scope_info.from?)
102
- end
71
+ # Note we need to pass the association's target class as an argument since it won't be known
72
+ # outside the context of an association instance for polymorphic associations.
73
+ def eager_loadable?(target_klass)
74
+ @eager_loadable_cache ||= Hash.new do |cache, target_klass_key|
75
+ cache[target_klass_key] = if scope.nil?
76
+ # Associations without any scoping options are eager loadable
77
+ true
78
+ elsif scope.arity > 0
79
+ # The scope will be evaluated for every model instance so it can't
80
+ # be eager loaded
81
+ false
82
+ else
83
+ scope_info = Goldiloader::ScopeInfo.new(scope_for(target_klass_key.unscoped))
84
+ scope_info.auto_include? &&
85
+ !scope_info.limit? &&
86
+ !scope_info.offset? &&
87
+ (!has_one? || !scope_info.order?)
88
+ end
89
+ end
90
+ @eager_loadable_cache[target_klass]
103
91
  end
104
92
  end
105
93
  ActiveRecord::Reflection::AssociationReflection.include(::Goldiloader::AssociationReflectionPatch)
@@ -126,7 +114,7 @@ module Goldiloader
126
114
  private
127
115
 
128
116
  def eager_loadable?
129
- reflection.eager_loadable? &&
117
+ klass && reflection.eager_loadable?(klass) &&
130
118
  (::Goldiloader::Compatibility.destroyed_model_associations_eager_loadable? || !owner.destroyed?)
131
119
  end
132
120
 
@@ -162,12 +150,7 @@ module Goldiloader
162
150
 
163
151
  module CollectionAssociationPatch
164
152
  # Force these methods to load the entire association for fully_load associations
165
- association_methods = [:size, :ids_reader, :empty?]
166
- if Goldiloader::Compatibility::ACTIVE_RECORD_VERSION < ::Gem::Version.new('5.1')
167
- association_methods.concat([:first, :second, :third, :fourth, :fifth, :last])
168
- end
169
-
170
- association_methods.each do |method|
153
+ [:size, :ids_reader, :empty?].each do |method|
171
154
  define_method(method) do |*args, &block|
172
155
  load_target if fully_load?
173
156
  super(*args, &block)
@@ -178,10 +161,8 @@ module Goldiloader
178
161
  load_with_auto_include { super }
179
162
  end
180
163
 
181
- if Goldiloader::Compatibility::ACTIVE_RECORD_VERSION >= ::Gem::Version.new('5.1')
182
- def find_from_target?
183
- fully_load? || super
184
- end
164
+ def find_from_target?
165
+ fully_load? || super
185
166
  end
186
167
  end
187
168
  ::ActiveRecord::Associations::CollectionAssociation.prepend(::Goldiloader::CollectionAssociationPatch)
@@ -15,17 +15,11 @@ module Goldiloader
15
15
  private
16
16
 
17
17
  def eager_load(models, association_name)
18
- ::ActiveRecord::Associations::Preloader.new.preload(models, [association_name])
19
- end
20
-
21
- def first_model_with_association(models, association_name)
22
- models.find { |model| has_association?(model, association_name) }
23
- end
24
-
25
- def associated_models(models, association_name)
26
- # We can't just do model.send(association_name) because the association method may have been
27
- # overridden
28
- models.map { |model| model.association(association_name).target }.flatten.compact.uniq
18
+ if Goldiloader::Compatibility.pre_rails_6_2?
19
+ ::ActiveRecord::Associations::Preloader.new.preload(models, [association_name])
20
+ else
21
+ ::ActiveRecord::Associations::Preloader.new(records: models, associations: [association_name]).call
22
+ end
29
23
  end
30
24
 
31
25
  def load?(model, association_name)
@@ -18,11 +18,7 @@ module Goldiloader
18
18
  end
19
19
 
20
20
  def register
21
- if Goldiloader::Compatibility.rails_4?
22
- ActiveRecord::Associations::Builder::Association.valid_options.concat(OPTIONS)
23
- else
24
- ActiveRecord::Associations::Builder::Association.extensions << AssociationBuilderExtension
25
- end
21
+ ActiveRecord::Associations::Builder::Association.extensions << AssociationBuilderExtension
26
22
  end
27
23
  end
28
24
  end
@@ -2,34 +2,17 @@
2
2
 
3
3
  module Goldiloader
4
4
  module Compatibility
5
- ACTIVE_RECORD_VERSION = ::Gem::Version.new(::ActiveRecord::VERSION::STRING)
5
+ ACTIVE_RECORD_VERSION = ::Gem::Version.new(::ActiveRecord::VERSION::STRING).release
6
+ PRE_RAILS_6_2 = ACTIVE_RECORD_VERSION < ::Gem::Version.new('6.2.0')
6
7
  RAILS_5_2_0 = ACTIVE_RECORD_VERSION == ::Gem::Version.new('5.2.0')
7
- PRE_RAILS_5_2 = ACTIVE_RECORD_VERSION < ::Gem::Version.new('5.2.0')
8
- POST_RAILS_5_1_4 = ACTIVE_RECORD_VERSION > ::Gem::Version.new('5.1.5')
9
- PRE_RAILS_5_1_5 = ACTIVE_RECORD_VERSION < ::Gem::Version.new('5.1.5')
10
- FROM_EAGER_LOADABLE = ACTIVE_RECORD_VERSION >= ::Gem::Version.new('5.1.5') ||
11
- (ACTIVE_RECORD_VERSION >= ::Gem::Version.new('5.0.7') && ACTIVE_RECORD_VERSION < ::Gem::Version.new('5.1.0'))
12
- GROUP_EAGER_LOADABLE = FROM_EAGER_LOADABLE
13
8
 
14
- def self.rails_4?
15
- ::ActiveRecord::VERSION::MAJOR == 4
16
- end
17
-
18
- def self.rails_5_0?
19
- ::ActiveRecord::VERSION::MAJOR == 5 && ::ActiveRecord::VERSION::MINOR == 0
9
+ def self.pre_rails_6_2?
10
+ PRE_RAILS_6_2
20
11
  end
21
12
 
22
13
  # See https://github.com/rails/rails/pull/32375
23
14
  def self.destroyed_model_associations_eager_loadable?
24
15
  !RAILS_5_2_0
25
16
  end
26
-
27
- def self.from_eager_loadable?
28
- FROM_EAGER_LOADABLE
29
- end
30
-
31
- def self.group_eager_loadable?
32
- GROUP_EAGER_LOADABLE
33
- end
34
17
  end
35
18
  end
@@ -21,11 +21,7 @@ module Goldiloader
21
21
  end
22
22
 
23
23
  def from?
24
- if Goldiloader::Compatibility.rails_4?
25
- scope.from_value.present?
26
- else
27
- scope.from_clause.present?
28
- end
24
+ scope.from_clause.present?
29
25
  end
30
26
 
31
27
  def group?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Goldiloader
4
- VERSION = '3.0.3'
4
+ VERSION = '4.0.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goldiloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Turkel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,40 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.3'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.3'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '4.2'
39
+ version: '5.2'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '5.3'
42
+ version: '7.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '4.2'
49
+ version: '5.2'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '5.3'
52
+ version: '7.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: appraisal
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -79,19 +79,19 @@ dependencies:
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
- name: coveralls
82
+ name: coveralls_reborn
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
- version: '0'
87
+ version: 0.18.0
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: '0'
94
+ version: 0.18.0
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: database_cleaner
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -148,20 +148,34 @@ dependencies:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
150
  version: '3'
151
+ - !ruby/object:Gem::Dependency
152
+ name: rspec_junit_formatter
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
151
165
  - !ruby/object:Gem::Dependency
152
166
  name: salsify_rubocop
153
167
  requirement: !ruby/object:Gem::Requirement
154
168
  requirements:
155
- - - '='
169
+ - - "~>"
156
170
  - !ruby/object:Gem::Version
157
- version: 0.52.1.1
171
+ version: 1.0.1
158
172
  type: :development
159
173
  prerelease: false
160
174
  version_requirements: !ruby/object:Gem::Requirement
161
175
  requirements:
162
- - - '='
176
+ - - "~>"
163
177
  - !ruby/object:Gem::Version
164
- version: 0.52.1.1
178
+ version: 1.0.1
165
179
  - !ruby/object:Gem::Dependency
166
180
  name: simplecov
167
181
  requirement: !ruby/object:Gem::Requirement
@@ -180,16 +194,16 @@ dependencies:
180
194
  name: sqlite3
181
195
  requirement: !ruby/object:Gem::Requirement
182
196
  requirements:
183
- - - ">="
197
+ - - "~>"
184
198
  - !ruby/object:Gem::Version
185
- version: '0'
199
+ version: '1.3'
186
200
  type: :development
187
201
  prerelease: false
188
202
  version_requirements: !ruby/object:Gem::Requirement
189
203
  requirements:
190
- - - ">="
204
+ - - "~>"
191
205
  - !ruby/object:Gem::Version
192
- version: '0'
206
+ version: '1.3'
193
207
  description: Automatically eager loads Rails associations as associations are traversed
194
208
  email:
195
209
  - jturkel@salsify.com
@@ -214,7 +228,7 @@ metadata:
214
228
  changelog_uri: https://github.com/salsify/goldiloader/blob/master/CHANGELOG.md
215
229
  source_code_uri: https://github.com/salsify/goldiloader/
216
230
  bug_tracker_uri: https://github.com/salsify/goldiloader/issues
217
- post_install_message:
231
+ post_install_message:
218
232
  rdoc_options: []
219
233
  require_paths:
220
234
  - lib
@@ -222,16 +236,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
236
  requirements:
223
237
  - - ">="
224
238
  - !ruby/object:Gem::Version
225
- version: '2.3'
239
+ version: '2.6'
226
240
  required_rubygems_version: !ruby/object:Gem::Requirement
227
241
  requirements:
228
242
  - - ">="
229
243
  - !ruby/object:Gem::Version
230
244
  version: '0'
231
245
  requirements: []
232
- rubyforge_project:
233
- rubygems_version: 2.6.14
234
- signing_key:
246
+ rubygems_version: 3.1.4
247
+ signing_key:
235
248
  specification_version: 4
236
249
  summary: Automatic Rails association eager loading
237
250
  test_files: []