n1_loader 1.4.1 → 1.4.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: fc06934b6c230d9b48dce18c7e9ee49afad4ab32d51d4550eb3e2916fe977656
4
- data.tar.gz: 456575999736bba2b4b8f33ff02a4908a7705b2cc31875bca9c80f3dbeeb4125
3
+ metadata.gz: f72c7428f78489c25222fb2ab8d56fde519c680fdc010115b952637c2291ca93
4
+ data.tar.gz: 7149852481ffed8d1fd0fc25e28fc045eda0a0f2936e748461dd7f43d4f709f1
5
5
  SHA512:
6
- metadata.gz: 4640cffcc0fe6e03672ba46fc16e9fc29fc33d1c18b6d9e54e4c6026cd0d0b465846a60e0b75ab0dec46fd4db21ae914a0f92d3cc4623e622b4782094d6ce680
7
- data.tar.gz: a010ffac1ce7604ce9434de734fa20f0e5162ff7307f6ddcafe0b9be1119a4f37d3774b7dd4beb8d36affd56e4f30830d01904406ce1f2b2fc2989d7f9910fa1
6
+ metadata.gz: 0d0802914b84d4c25a97c8c328ff2ae4453cf8fcd4eee87de1955b06b810c874d9982498b5fc80ecf1fa77238971e51ef5f162f809914876a1811084b366ddfe
7
+ data.tar.gz: fa001ab34b7165ee35ba31ef449c837418d538e52977ee984b38e35b767df06c05ef0cb01949c9290c17ae40bcd3e3644f00374cf7f66d7e6811f094515c37da
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.4.2] - 2022-03-01
2
+
3
+ - Add n1_clear_cache method which is useful for cases like reload in ActiveRecord
4
+
1
5
  ## [1.4.1] - 2022-02-24
2
6
 
3
7
  - Fix preloading of invalid objects
data/README.md CHANGED
@@ -129,6 +129,9 @@ end
129
129
  user = User.new
130
130
  user.orders_count # => loader is executed first time and value was cached
131
131
  user.orders_count(reload: true) # => loader is executed again and a new value was cached
132
+ # or
133
+ user.n1_clear_cache
134
+ user.orders_count
132
135
 
133
136
  users = [User.new, User.new]
134
137
  N1Loader::Preloader.new(users).preload(:orders_count) # => loader was initialized but not yet executed
@@ -32,6 +32,12 @@ module N1Loader
32
32
  send("#{name}_loader=", loader_collection)
33
33
  end
34
34
 
35
+ def n1_clear_cache
36
+ self.class.n1_loaders.each do |name|
37
+ n1_loader_set(name, nil)
38
+ end
39
+ end
40
+
35
41
  def self.included(base)
36
42
  base.extend(ClassMethods)
37
43
  end
@@ -45,6 +51,10 @@ module N1Loader
45
51
  respond_to?("#{name}_loader")
46
52
  end
47
53
 
54
+ def n1_loaders
55
+ @n1_loaders ||= superclass.respond_to?(:n1_loaders) ? superclass.n1_loaders.dup : []
56
+ end
57
+
48
58
  def n1_optimized(name, loader = nil, &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
49
59
  loader ||= Class.new(N1Loader::Loader) do
50
60
  if block.arity == 1
@@ -56,6 +66,8 @@ module N1Loader
56
66
  loader_name = "#{name}_loader"
57
67
  loader_variable_name = "@#{loader_name}"
58
68
 
69
+ n1_loaders << name
70
+
59
71
  define_singleton_method(loader_name) do
60
72
  loader
61
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module N1Loader
4
- VERSION = "1.4.1"
4
+ VERSION = "1.4.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: n1_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-24 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord