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 +4 -4
- data/CHANGELOG.md +45 -0
- data/lib/n1_loader/core/loader.rb +10 -12
- data/lib/n1_loader/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9be9c5e7d5e551d253a327cd3d130a38821ef49a43cab60235cc5363a4093d0
|
4
|
+
data.tar.gz: 55c8e748bf52fc05b8648d81d907963b4a60eae0b7aa680d0c491987b43303d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
65
|
+
def check_missing_arguments! # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
66
66
|
return unless (arguments = self.class.arguments)
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
required_arguments = arguments.reject { |argument| argument[:optional] }
|
69
|
+
.map { |argument| argument[:name] }
|
70
70
|
|
71
|
-
return if
|
71
|
+
return if required_arguments.all? { |argument| args.key?(argument) }
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
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,
|
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 = {}
|
109
|
+
@loaded = {}
|
112
110
|
|
113
111
|
if respond_to?(:single) && elements.size == 1
|
114
112
|
fulfill(elements.first, single(elements.first))
|
data/lib/n1_loader/version.rb
CHANGED