goldiloader 3.2.0 → 4.0.0

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
  SHA256:
3
- metadata.gz: f5ec15cfc51915f390119375f633b3438f08226e9ebac6e8523c46e69f91e16c
4
- data.tar.gz: 61894b325643cc364eaea59e9b3d16aa25f32a76aabbd0f30a126355dbd6d365
3
+ metadata.gz: 2b1702016efdeb47b12f583ff299bc46125714acc053b7c8594a9cf9a4fcba07
4
+ data.tar.gz: 6485555c4d71199683907813d9563fdecce3c8bada819d7ae1180f48ad5afadb
5
5
  SHA512:
6
- metadata.gz: b792fb0a79df0076eddbe2e451d7df31583bb2a7d6cd90c2aa50c3f55bc97839367f6f006e82688eab3f2d0e3e056a5a3ba9b881095f8ae88dbed3aedc44d1f5
7
- data.tar.gz: 920bb6c789be76a3e10c9bff4d74026d7ea7ceb18575217bccf5bfa3bf05653e093f0ea3a4188c5e14167e81d7fecced7578fcd81eca9abe19126543f54362a0
6
+ metadata.gz: 949fc36b600662dde9597b87c26430949bbdc12dff2d2eb9845405dcb273c2c9621edbb8d850f95dd602c892687dffc95849243bbd94c4e3473c31932f48464a
7
+ data.tar.gz: 5d645a33f703ad458096af205535efcd5cebb2ab802ae0af8203cc6236f388a73d79ec0c08681c447dbbe4b057a29a0bd373c001ce277dd34285447614f138a8
@@ -51,13 +51,7 @@ module Goldiloader
51
51
  end
52
52
 
53
53
  def auto_include_value=(value)
54
- if Goldiloader::Compatibility.rails_4?
55
- raise ::ActiveRecord::Relation::ImmutableRelation if @loaded
56
- check_cached_relation
57
- else
58
- assert_mutability!
59
- end
60
-
54
+ assert_mutability!
61
55
  @values[:auto_include] = value
62
56
  end
63
57
  end
@@ -85,17 +79,11 @@ module Goldiloader
85
79
  # be eager loaded
86
80
  false
87
81
  else
88
- scope_info = if Goldiloader::Compatibility.rails_4?
89
- Goldiloader::ScopeInfo.new(klass.unscoped.instance_exec(&scope) || klass.unscoped)
90
- else
91
- Goldiloader::ScopeInfo.new(scope_for(klass.unscoped))
92
- end
82
+ scope_info = Goldiloader::ScopeInfo.new(scope_for(klass.unscoped))
93
83
  scope_info.auto_include? &&
94
84
  !scope_info.limit? &&
95
85
  !scope_info.offset? &&
96
- (!has_one? || !scope_info.order?) &&
97
- (::Goldiloader::Compatibility.group_eager_loadable? || !scope_info.group?) &&
98
- (::Goldiloader::Compatibility.from_eager_loadable? || !scope_info.from?)
86
+ (!has_one? || !scope_info.order?)
99
87
  end
100
88
  end
101
89
  end
@@ -159,12 +147,7 @@ module Goldiloader
159
147
 
160
148
  module CollectionAssociationPatch
161
149
  # Force these methods to load the entire association for fully_load associations
162
- association_methods = [:size, :ids_reader, :empty?]
163
- if Goldiloader::Compatibility::ACTIVE_RECORD_VERSION < ::Gem::Version.new('5.1')
164
- association_methods.concat([:first, :second, :third, :fourth, :fifth, :last])
165
- end
166
-
167
- association_methods.each do |method|
150
+ [:size, :ids_reader, :empty?].each do |method|
168
151
  define_method(method) do |*args, &block|
169
152
  load_target if fully_load?
170
153
  super(*args, &block)
@@ -175,10 +158,8 @@ module Goldiloader
175
158
  load_with_auto_include { super }
176
159
  end
177
160
 
178
- if Goldiloader::Compatibility::ACTIVE_RECORD_VERSION >= ::Gem::Version.new('5.1')
179
- def find_from_target?
180
- fully_load? || super
181
- end
161
+ def find_from_target?
162
+ fully_load? || super
182
163
  end
183
164
  end
184
165
  ::ActiveRecord::Associations::CollectionAssociation.prepend(::Goldiloader::CollectionAssociationPatch)
@@ -15,7 +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])
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
19
23
  end
20
24
 
21
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,27 +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
- FROM_EAGER_LOADABLE = ACTIVE_RECORD_VERSION >= ::Gem::Version.new('5.1.5') ||
8
- (ACTIVE_RECORD_VERSION >= ::Gem::Version.new('5.0.7') && ACTIVE_RECORD_VERSION < ::Gem::Version.new('5.1.0'))
9
- GROUP_EAGER_LOADABLE = FROM_EAGER_LOADABLE
10
8
 
11
- def self.rails_4?
12
- ::ActiveRecord::VERSION::MAJOR == 4
9
+ def self.pre_rails_6_2?
10
+ PRE_RAILS_6_2
13
11
  end
14
12
 
15
13
  # See https://github.com/rails/rails/pull/32375
16
14
  def self.destroyed_model_associations_eager_loadable?
17
15
  !RAILS_5_2_0
18
16
  end
19
-
20
- def self.from_eager_loadable?
21
- FROM_EAGER_LOADABLE
22
- end
23
-
24
- def self.group_eager_loadable?
25
- GROUP_EAGER_LOADABLE
26
- end
27
17
  end
28
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.2.0'
4
+ VERSION = '4.0.0'
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.2.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Turkel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-02-08 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: '6.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: '6.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: '6.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: '6.3'
52
+ version: '7.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: appraisal
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -166,16 +166,16 @@ dependencies:
166
166
  name: salsify_rubocop
167
167
  requirement: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - '='
169
+ - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: 0.52.1.1
171
+ version: 1.0.1
172
172
  type: :development
173
173
  prerelease: false
174
174
  version_requirements: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - '='
176
+ - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: 0.52.1.1
178
+ version: 1.0.1
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: simplecov
181
181
  requirement: !ruby/object:Gem::Requirement
@@ -236,14 +236,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
236
  requirements:
237
237
  - - ">="
238
238
  - !ruby/object:Gem::Version
239
- version: '2.3'
239
+ version: '2.6'
240
240
  required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  requirements:
242
242
  - - ">="
243
243
  - !ruby/object:Gem::Version
244
244
  version: '0'
245
245
  requirements: []
246
- rubygems_version: 3.0.8
246
+ rubygems_version: 3.1.4
247
247
  signing_key:
248
248
  specification_version: 4
249
249
  summary: Automatic Rails association eager loading