ar_lazy_preload 0.2.7 → 0.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18865f27f303c041869d4cbeb759d90adde8f2255b970d0752d789b0604f3846
|
4
|
+
data.tar.gz: f6818b6e38baf72a2bd8881c6727a70fc01a4c90916ed888cf0e51c837858851
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81e6e8d0dc2ced79052f0b05018a87353abbf416ee234ff6f00c98fa22912a08b4161bece20f78187d25c9221a13ba2f4bea7450916f4f32900e0c60dac99d6e
|
7
|
+
data.tar.gz: 5f970163332f177b5dbfbbe000fbbca4174bfe822d512ceb3bfa2263a769dfd438d39d7faf2cc516f7d05a7cfb1bd5b2bf1377ec7592312b9a6f7f75e92602fa
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ArLazyPreload
|
4
|
+
# ActiveRecord::CollectionAssociation patch with a hook for lazy preloading
|
5
|
+
module CollectionAssociation
|
6
|
+
# rubocop:disable Metrics/AbcSize
|
7
|
+
def ids_reader
|
8
|
+
return super if owner.lazy_preload_context.blank?
|
9
|
+
|
10
|
+
primary_key = reflection.association_primary_key.to_sym
|
11
|
+
if loaded?
|
12
|
+
target.map(&primary_key)
|
13
|
+
elsif !target.empty?
|
14
|
+
load_target.map(&primary_key)
|
15
|
+
else
|
16
|
+
@association_ids ||= reader.map(&primary_key)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# rubocop:enable Metrics/AbcSize
|
20
|
+
end
|
21
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require "ar_lazy_preload/active_record/base"
|
4
4
|
require "ar_lazy_preload/active_record/relation"
|
5
5
|
require "ar_lazy_preload/active_record/association"
|
6
|
+
require "ar_lazy_preload/active_record/collection_association"
|
6
7
|
require "ar_lazy_preload/active_record/merger"
|
7
8
|
require "ar_lazy_preload/active_record/association_relation"
|
8
9
|
require "ar_lazy_preload/active_record/collection_proxy"
|
@@ -22,6 +23,7 @@ module ArLazyPreload
|
|
22
23
|
ActiveRecord::Associations::Association
|
23
24
|
].each { |klass| klass.prepend(Association) }
|
24
25
|
|
26
|
+
ActiveRecord::Associations::CollectionAssociation.prepend(CollectionAssociation)
|
25
27
|
ActiveRecord::Associations::CollectionProxy.prepend(CollectionProxy)
|
26
28
|
end
|
27
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_lazy_preload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/ar_lazy_preload/active_record/association.rb
|
165
165
|
- lib/ar_lazy_preload/active_record/association_relation.rb
|
166
166
|
- lib/ar_lazy_preload/active_record/base.rb
|
167
|
+
- lib/ar_lazy_preload/active_record/collection_association.rb
|
167
168
|
- lib/ar_lazy_preload/active_record/collection_proxy.rb
|
168
169
|
- lib/ar_lazy_preload/active_record/merger.rb
|
169
170
|
- lib/ar_lazy_preload/active_record/relation.rb
|