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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -0
- data/lib/n1_loader/core/loadable.rb +12 -0
- data/lib/n1_loader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f72c7428f78489c25222fb2ab8d56fde519c680fdc010115b952637c2291ca93
|
4
|
+
data.tar.gz: 7149852481ffed8d1fd0fc25e28fc045eda0a0f2936e748461dd7f43d4f709f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d0802914b84d4c25a97c8c328ff2ae4453cf8fcd4eee87de1955b06b810c874d9982498b5fc80ecf1fa77238971e51ef5f162f809914876a1811084b366ddfe
|
7
|
+
data.tar.gz: fa001ab34b7165ee35ba31ef449c837418d538e52977ee984b38e35b767df06c05ef0cb01949c9290c17ae40bcd3e3644f00374cf7f66d7e6811f094515c37da
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/n1_loader/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2022-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|