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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f72c7428f78489c25222fb2ab8d56fde519c680fdc010115b952637c2291ca93
4
- data.tar.gz: 7149852481ffed8d1fd0fc25e28fc045eda0a0f2936e748461dd7f43d4f709f1
3
+ metadata.gz: fe90c7df57ebf6237efd043aafd9a988415182d86ec877dedb02b1afb2b28295
4
+ data.tar.gz: 0bd43d92e0de325a413f0f88680cc9cb9c79b2e165cbae1cfe7bd9b175c4ee2f
5
5
  SHA512:
6
- metadata.gz: 0d0802914b84d4c25a97c8c328ff2ae4453cf8fcd4eee87de1955b06b810c874d9982498b5fc80ecf1fa77238971e51ef5f162f809914876a1811084b366ddfe
7
- data.tar.gz: fa001ab34b7165ee35ba31ef449c837418d538e52977ee984b38e35b767df06c05ef0cb01949c9290c17ae40bcd3e3644f00374cf7f66d7e6811f094515c37da
6
+ metadata.gz: d44ce33e6d822ee2121e5adf436c4841d92c89abc4fc98bace13371602987d21e813c530ddf1bf07b3fe5cbe42ba79bb71520a7161c37e95bd304dcca803d31d
7
+ data.tar.gz: 1391dd9fa95f7e267e1e5c684a1dddbb025982f3fbf2c56207f1e868972b0ee4efafbca5919c781abf6a2bc8e85ce3d9251b8762d357d1bc82592b2d1ba540d4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.4.3] - 2022-04-13
2
+
3
+ - Add `default` support to arguments
4
+
1
5
  ## [1.4.2] - 2022-03-01
2
6
 
3
7
  - Add n1_clear_cache method which is useful for cases like reload in ActiveRecord
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module N1Loader
4
- VERSION = "1.4.2"
4
+ VERSION = "1.4.3"
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.2
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-03-01 00:00:00.000000000 Z
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.2.22
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.