n1_loader 1.4.2 → 1.4.3
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 +21 -1
- data/lib/n1_loader/core/loader.rb +4 -1
- data/lib/n1_loader/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe90c7df57ebf6237efd043aafd9a988415182d86ec877dedb02b1afb2b28295
|
4
|
+
data.tar.gz: 0bd43d92e0de325a413f0f88680cc9cb9c79b2e165cbae1cfe7bd9b175c4ee2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44ce33e6d822ee2121e5adf436c4841d92c89abc4fc98bace13371602987d21e813c530ddf1bf07b3fe5cbe42ba79bb71520a7161c37e95bd304dcca803d31d
|
7
|
+
data.tar.gz: 1391dd9fa95f7e267e1e5c684a1dddbb025982f3fbf2c56207f1e868972b0ee4efafbca5919c781abf6a2bc8e85ce3d9251b8762d357d1bc82592b2d1ba540d4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -31,11 +31,31 @@ gem 'n1_loader'
|
|
31
31
|
You can add integration with [ActiveRecord][5] by:
|
32
32
|
```ruby
|
33
33
|
gem 'n1_loader', require: 'n1_loader/active_record'
|
34
|
+
|
35
|
+
# You also may be interested in injecting it to models
|
36
|
+
class ActiveRecord::Base
|
37
|
+
include N1Loader::Loadable
|
38
|
+
|
39
|
+
def reload(*)
|
40
|
+
n1_clear_cache
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
34
44
|
```
|
35
45
|
|
36
46
|
You can add the integration with [ActiveRecord][5] and [ArLazyPreload][6] by:
|
37
47
|
```ruby
|
38
48
|
gem 'n1_loader', require: 'n1_loader/ar_lazy_preload'
|
49
|
+
|
50
|
+
# You also may be interested in injecting it to models
|
51
|
+
class ActiveRecord::Base
|
52
|
+
include N1Loader::Loadable
|
53
|
+
|
54
|
+
def reload(*)
|
55
|
+
n1_clear_cache
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
39
59
|
```
|
40
60
|
|
41
61
|
## Usage
|
@@ -220,7 +240,7 @@ class User
|
|
220
240
|
include N1Loader::Loadable
|
221
241
|
|
222
242
|
n1_optimized :orders_count do
|
223
|
-
argument :sale
|
243
|
+
argument :sale, optional: true, default: -> { Sale.last }
|
224
244
|
|
225
245
|
cache_key { sale.id }
|
226
246
|
|
@@ -17,10 +17,13 @@ module N1Loader
|
|
17
17
|
# @param name [Symbol]
|
18
18
|
# @param opts [Hash]
|
19
19
|
# @option opts [Boolean] optional false by default
|
20
|
+
# @option opts [Proc] default
|
20
21
|
def argument(name, **opts)
|
22
|
+
opts[:optional] = true if opts[:default]
|
23
|
+
|
21
24
|
@arguments ||= []
|
22
25
|
|
23
|
-
define_method(name) { args[name] }
|
26
|
+
define_method(name) { args[name] ||= opts[:default]&.call }
|
24
27
|
|
25
28
|
@arguments << opts.merge(name: name)
|
26
29
|
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.3
|
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-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.1.6
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Loader to solve N+1 issue for good.
|