n1_loader 1.6.2 → 1.6.4

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: b8a914cabc2c837109b3f6f72b78dbbc4b6e64b87049568e9c6733f29b2a6867
4
- data.tar.gz: ce9b88ee6121de3540dd13789da0c28b8c01e32598ed1dacb10af16da05e82b9
3
+ metadata.gz: 7dbd6c49bba45473f2a822d02befa1ca0efdc155698648a17640c472ace4fccd
4
+ data.tar.gz: db6c04d5cc63ddbcc8a3362fba985f478601e2b5ed0f5a298df992ecdc1e8f65
5
5
  SHA512:
6
- metadata.gz: 1a290cee96e8ba97c181267efde4f94ca494037d05e4cce93e58131faa4f6cc22c072a792e24631479b41a62cdfff0857e3dd3f51252cf7d05a4f3252eb41c5b
7
- data.tar.gz: b4fcf0e7f3911441d542b6ab5d9f657671dcbf7864822f11c2e6854d957e49787026490f4595323c14d60348259eef5a522da4312fe6ee8ccd78a092437d8346
6
+ metadata.gz: 397c84c6ee33547838c1155c58f7488dfef34028003d7da1c26a6f9a0f2be951bfe4ff4d7df761be6185ec58e36022ead691e434af708fd74ccb2cbae503e459
7
+ data.tar.gz: 4a554a0f7aa8832b7aa81f32e8b0544baf060c0c8b59538f56e7d579b0e972e680a989ff41c7fe14c01665a7a2f8fb3883ca7ef98d60cc24005a68d3fe67bc6d
@@ -16,7 +16,6 @@ jobs:
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  ruby-version: 2.7
19
- bundler-cache: true
20
19
 
21
20
  - name: Install dependencies
22
21
  run: bundle install
@@ -38,6 +38,9 @@ jobs:
38
38
  - activerecord-gemfile: 'ar_7_latest'
39
39
  ar_lazy_preload-gemfile: 'ar_lazy_preload_0.6.1'
40
40
 
41
+ - activerecord-gemfile: 'ar_5_latest'
42
+ ar_lazy_preload-gemfile: 'ar_lazy_preload_master'
43
+
41
44
  env:
42
45
  ACTIVERECORD_GEMFILE: ${{ matrix.activerecord-gemfile }}
43
46
  AR_LAZY_PRELOAD_GEMFILE: ${{ matrix.ar_lazy_preload-gemfile }}
@@ -49,7 +52,6 @@ jobs:
49
52
  uses: ruby/setup-ruby@v1
50
53
  with:
51
54
  ruby-version: ${{ matrix.ruby-version }}
52
- bundler-cache: true
53
55
 
54
56
  - name: Install dependencies
55
57
  run: bundle install
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.6.4] - 2023/07/30
2
+
3
+ - Add support of `n1_optimized` ending with `?` (question mark). Thanks [Ilya Kamenko](https://github.com/Galathius) for the suggestion!
4
+
5
+ ## [1.6.3] - 2022/12/30
6
+
7
+ - Performance optimization: avoid unnecessary calls. Thanks [Nazar Matus](https://github.com/FunkyloverOne) for the [contribution](https://github.com/djezzzl/n1_loader/pull/33).
8
+
1
9
  ## [1.6.2] - 2022/11/23
2
10
 
3
11
  - Add fund metadata
data/README.md CHANGED
@@ -17,6 +17,12 @@ For example, it can help with resolving N+1 for:
17
17
 
18
18
  ___Support:___ ActiveRecord 5, 6, and 7.
19
19
 
20
+ Follow me and stay tuned for the updates:
21
+ - [LinkedIn](https://www.linkedin.com/in/evgeniydemin/)
22
+ - [Medium](https://evgeniydemin.medium.com/)
23
+ - [Twitter](https://twitter.com/EvgeniyDemin/)
24
+ - [GitHub](https://github.com/djezzzl)
25
+
20
26
  ## Killer feature for GraphQL API
21
27
 
22
28
  N1Loader in combination with [ArLazyPreload][6] is a killer feature for your GraphQL API.
@@ -9,7 +9,7 @@ module N1Loader
9
9
  # # with inline loader
10
10
  # n1_loader :something do
11
11
  # def perform(elements)
12
- # elements.each { |element| fulfill(element,, element.calculate_something) }
12
+ # elements.each { |element| fulfill(element, element.calculate_something) }
13
13
  # end
14
14
  # end
15
15
  #
@@ -20,15 +20,21 @@ module N1Loader
20
20
  # # custom loader
21
21
  # class MyLoader < N1Loader::Loader
22
22
  # def perform(elements)
23
- # elements.each { |element| fulfill(element,, element.calculate_something) }
23
+ # elements.each { |element| fulfill(element, element.calculate_something) }
24
24
  # end
25
25
  # end
26
26
  module Loadable
27
+ include Name
28
+
27
29
  def n1_loader(name)
30
+ name = n1_loader_name(name)
31
+
28
32
  send("#{name}_loader")
29
33
  end
30
34
 
31
35
  def n1_loader_set(name, loader_collection)
36
+ name = n1_loader_name(name)
37
+
32
38
  send("#{name}_loader=", loader_collection)
33
39
  end
34
40
 
@@ -43,11 +49,17 @@ module N1Loader
43
49
  end
44
50
 
45
51
  module ClassMethods # :nodoc:
52
+ include Name
53
+
46
54
  def n1_loader(name)
55
+ name = n1_loader_name(name)
56
+
47
57
  send("#{name}_loader")
48
58
  end
49
59
 
50
60
  def n1_loader_defined?(name)
61
+ name = n1_loader_name(name)
62
+
51
63
  respond_to?("#{name}_loader")
52
64
  end
53
65
 
@@ -63,7 +75,7 @@ module N1Loader
63
75
  class_eval(&block)
64
76
  end
65
77
  end
66
- loader_name = "#{name}_loader"
78
+ loader_name = "#{n1_loader_name(name)}_loader"
67
79
  loader_variable_name = "@#{loader_name}"
68
80
 
69
81
  n1_loaders << name
@@ -110,7 +110,7 @@ module N1Loader
110
110
 
111
111
  @loaded = {}.compare_by_identity
112
112
 
113
- if elements.size == 1 && respond_to?(:single)
113
+ if respond_to?(:single) && elements.size == 1
114
114
  fulfill(elements.first, single(elements.first))
115
115
  elsif elements.any?
116
116
  perform(elements)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module N1Loader
4
+ # Add support of question mark names
5
+ module Name
6
+ def n1_loader_name(name)
7
+ to_sym = name.is_a?(Symbol)
8
+
9
+ converted = name.to_s.gsub("?", "_question_mark")
10
+
11
+ to_sym ? converted.to_sym : converted
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module N1Loader
4
- VERSION = "1.6.2"
4
+ VERSION = "1.6.4"
5
5
  end
data/lib/n1_loader.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "n1_loader/version"
4
4
 
5
+ require_relative "n1_loader/core/name"
5
6
  require_relative "n1_loader/core/loader"
6
7
  require_relative "n1_loader/core/loader_collection"
7
8
  require_relative "n1_loader/core/loadable"
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.6.2
4
+ version: 1.6.4
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-23 00:00:00.000000000 Z
11
+ date: 2023-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -196,6 +196,7 @@ files:
196
196
  - lib/n1_loader/core/loadable.rb
197
197
  - lib/n1_loader/core/loader.rb
198
198
  - lib/n1_loader/core/loader_collection.rb
199
+ - lib/n1_loader/core/name.rb
199
200
  - lib/n1_loader/core/preloader.rb
200
201
  - lib/n1_loader/version.rb
201
202
  - n1_loader.gemspec