ar_lazy_preload 0.3.1 → 0.3.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69e0b3d4a8e8ac0c7c3824058347406f2ede573183f085b40acfd288e2b43014
|
4
|
+
data.tar.gz: d47fa44acb9b48181ac97c4c77138977375e1f593b4eaee4673314895836220f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73f6f5dd9b745e262d5e2e1e6532f266c65eda63282938e2b08838cbb1bf4e161df8a38d208c436714967d13ef2579a6398c492b3690f98d5d9a082169d93065
|
7
|
+
data.tar.gz: 5f084968e4c8aacdf438ab08f94e2768f9090185e91c1ce4e9f7841558d0541b42f8e3b9926df85191d634b01cbcb1aab9e7702b77a2eb438cf0b732017e9322
|
data/README.md
CHANGED
@@ -44,6 +44,12 @@ ArLazyPreload.config.auto_preload = true
|
|
44
44
|
|
45
45
|
After that there is no need to call `#lazy_preload` on the association, everything would be loaded lazily.
|
46
46
|
|
47
|
+
If you want to turn automatic preload off for a specific record, you can call `.skip_preload` before any associations method:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
users.first.skip_preload.posts # => SELECT * FROM posts WHERE user_id = ?
|
51
|
+
```
|
52
|
+
|
47
53
|
## Installation
|
48
54
|
|
49
55
|
Add this line to your application's Gemfile, and you're all set:
|
@@ -10,5 +10,11 @@ module ArLazyPreload
|
|
10
10
|
attr_accessor :lazy_preload_context
|
11
11
|
|
12
12
|
delegate :try_preload_lazily, to: :lazy_preload_context, allow_nil: true
|
13
|
+
|
14
|
+
def skip_preload
|
15
|
+
lazy_preload_context&.records&.delete(self)
|
16
|
+
self.lazy_preload_context = nil
|
17
|
+
self
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module ArLazyPreload
|
4
4
|
# ActiveRecord::CollectionAssociation patch with a hook for lazy preloading
|
5
5
|
module CollectionAssociation
|
6
|
-
# rubocop:disable Metrics/AbcSize
|
6
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
7
7
|
def ids_reader
|
8
8
|
return super if owner.lazy_preload_context.blank?
|
9
9
|
|
@@ -16,6 +16,6 @@ module ArLazyPreload
|
|
16
16
|
@association_ids ||= reader.map(&primary_key)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
# rubocop:enable Metrics/AbcSize
|
19
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
20
20
|
end
|
21
21
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|