n1_loader 1.6.5 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b7ac1fa217041b1142d51fe619c44f6f1cbc16e2d7c2606c5cb4f023f7a19ac
4
- data.tar.gz: a62833353c2699c369d3581b239f0b8f67b87b6435cc4cba4995661bc83c9174
3
+ metadata.gz: e9be9c5e7d5e551d253a327cd3d130a38821ef49a43cab60235cc5363a4093d0
4
+ data.tar.gz: 55c8e748bf52fc05b8648d81d907963b4a60eae0b7aa680d0c491987b43303d3
5
5
  SHA512:
6
- metadata.gz: c4f17f1bb93729de61ecbd636837323070c65a48f54b4fb6917cf1b24bc5a2b416826498eca11722779aafca09c9f4df150687aed331b6dae2fa9172c024aab4
7
- data.tar.gz: 102ed2741ad8af210182576df8ceba4293d829b0c4489d6f15a5823dcfe0de976a4ecb604c57fe6383cdf243cc2e4fc510a3f1d8ee1d1e4cfc0c7b5ec0941e65
6
+ metadata.gz: b626c836856198a9e0d0f54daedd0299b2cd7eb0648ddde369a6b7f923751b31d402c8ba03ab67bb064b884e5c5f035babcd1f59d0bef93db26968f7e6fca7ae
7
+ data.tar.gz: 640e8decd4c53e4f09451041392b964b5f0e59a273719673978e4bf62d26543364b5b4166d97833b7a5084ebacfe7921a921a5c0aae3938c3ce9394f6627bfc8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ ## [1.6.7] - 2023/07/30
2
+
3
+ Extend the flexibility of loading data comparison. Thanks [Nazar Matus](https://github.com/FunkyloverOne) for suggesting it!
4
+
5
+ **BREAKING CHANGES:**
6
+
7
+ Loose comparison of loaded data. Before loaded data was initialized with identity comparator in mind:
8
+
9
+ ```ruby
10
+ @loaded = {}.compare_by_identity
11
+ ```
12
+
13
+ Now it will be:
14
+
15
+ ```ruby
16
+ @loaded = {}
17
+ ```
18
+
19
+ This might bring unwanted results for cases when strict comparison was wanted.
20
+
21
+ On the other hand, it gives more flexibility for many other cases, especially with isolated loader.
22
+ For example, this will work now, when it wasn't working before.
23
+
24
+ ```ruby
25
+ # ActiveRecord object
26
+ object = Entity.first
27
+
28
+ # Initialize isolated loader
29
+ instance = loader.new([object])
30
+
31
+ # This was working before because the loaded object is identical to passed object by `#object_id`
32
+ instance.for(object)
33
+
34
+ # This wasn't working before because the loaded object is not identical to passed one by `#object_id`
35
+ #
36
+ # But it will be working now, because object == Entity.find(object.id)
37
+ instance.for(Entity.find(object.id))
38
+ ```
39
+
40
+ If you need strict comparison support, please feel free to open the issue or the PR.
41
+
42
+ ## [1.6.6] - 2023/07/30
43
+
44
+ - Fix naive check of required arguments. Thanks [Nazar Matus](https://github.com/FunkyloverOne) for the issue!
45
+
1
46
  ## [1.6.5] - 2023/07/30
2
47
 
3
48
  - Fix nested preloading for ActiveRecord 7. Thanks [Igor Gonchar](https://github.com/gigorok) for the issue!
@@ -62,22 +62,20 @@ module N1Loader
62
62
 
63
63
  attr_reader :elements, :args
64
64
 
65
- def check_missing_arguments! # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
65
+ def check_missing_arguments! # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
66
66
  return unless (arguments = self.class.arguments)
67
67
 
68
- min = arguments.count { |argument| !argument[:optional] }
69
- max = arguments.count
68
+ required_arguments = arguments.reject { |argument| argument[:optional] }
69
+ .map { |argument| argument[:name] }
70
70
 
71
- return if args.size >= min && args.size <= max
71
+ return if required_arguments.all? { |argument| args.key?(argument) }
72
72
 
73
- str =
74
- if min == max
75
- max.to_s
76
- else
77
- "#{min}..#{max}"
78
- end
73
+ missing_arguments = required_arguments.reject { |argument| args.key?(argument) }
74
+
75
+ list = missing_arguments.map { |argument| ":#{argument}" }.join(", ")
79
76
 
80
- raise MissingArgument, "Loader requires #{str} arguments but #{args.size} were given"
77
+ raise MissingArgument,
78
+ "Loader requires [#{list}] arguments but they are missing"
81
79
  end
82
80
 
83
81
  def check_arguments!
@@ -108,7 +106,7 @@ module N1Loader
108
106
 
109
107
  check_arguments!
110
108
 
111
- @loaded = {}.compare_by_identity
109
+ @loaded = {}
112
110
 
113
111
  if respond_to?(:single) && elements.size == 1
114
112
  fulfill(elements.first, single(elements.first))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module N1Loader
4
- VERSION = "1.6.5"
4
+ VERSION = "1.7.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: n1_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin