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: b8f6aa06d7f037bd8762f0000db03adde926f41ee536ec4faac8b1f3ca93ff1e
4
- data.tar.gz: c6a8b59093090fc898692c102acda5ed949a34846605b65a6f27b89b940d2d46
3
+ metadata.gz: 69e0b3d4a8e8ac0c7c3824058347406f2ede573183f085b40acfd288e2b43014
4
+ data.tar.gz: d47fa44acb9b48181ac97c4c77138977375e1f593b4eaee4673314895836220f
5
5
  SHA512:
6
- metadata.gz: 41abf78b2668b8f39c5713a72a6536a57f660bea16bdebdb4a2f1d069c86285d0455c2d193d46f2dbe12551e12d823c1187163223193826d3861154f67c03c1d
7
- data.tar.gz: 7cd15b8bf27071baa258992e99a726e9b49f25ea5d8edb2802fa9d2e30ce652bb204acfb131b8e0adff33f178a6a1d322e4717e2f8339da4224765a5da92ca30
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArLazyPreload
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  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.1
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-10 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails