n1_loader 1.6.6 → 1.7.1

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: f7d5587fbac0376006abf03b7beb385547b1c9206cdeea8461d9bf07b67e0df4
4
- data.tar.gz: 6f94574d65b49c528a6af3e06d6d816ed78ef3cf3f6e14002249b816526cbb4a
3
+ metadata.gz: 35755dbc6a0ae17e636a26aaa99d903714a2e61248f60cc7a6c23f0d1ff5cbdd
4
+ data.tar.gz: 34ebd3c7c2d873fb42fce414c74055251ef6169df1a06ec6255a857598c8fdf7
5
5
  SHA512:
6
- metadata.gz: 39d0370fee07be7e080adb22392633366da8cce0b74228c728b8647e9f7f859b4c995346bf0a8e9b477c355374b29f4f4690f089c6b6904822af3cfba88685af
7
- data.tar.gz: 0245c5ba26df1d3f3508a22143ae5cb9d708c5460ef218ee2193b8cc537bf0ee6f6838357be50fe4d2d2d4c1db050e76a6176e98b3b7df4c64af4bf7b0e35e36
6
+ metadata.gz: b4233a0b750ccfa3e001b512a379fb5a68758c45117fdaa0b5ec9cfd1c84d344c7e261ee61927794db2246aaa6c40b9576d5a19d1e547e65f6e08eab21de903d
7
+ data.tar.gz: ee26e611bf87f7daf78912f01996bd7330a0dbb0d74e18a38af79b7f4869b6c43365694ef5f8597a8f1574e5cb16ff1ca4bf73421019215b29f139e4917510e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ ## [1.7.1] - 2023/07/30
2
+
3
+ - Fix interface discrepancy for `N1LoaderReflection`. Thanks [Denis Talakevich](https://github.com/senid231) for suggesting it!
4
+
5
+ ## [1.7.0] - 2023/07/30
6
+
7
+ Extend the flexibility of loading data comparison. Thanks [Nazar Matus](https://github.com/FunkyloverOne) for suggesting it!
8
+
9
+ **BREAKING CHANGES:**
10
+
11
+ Loose comparison of loaded data. Before loaded data was initialized with identity comparator in mind:
12
+
13
+ ```ruby
14
+ @loaded = {}.compare_by_identity
15
+ ```
16
+
17
+ Now it will be:
18
+
19
+ ```ruby
20
+ @loaded = {}
21
+ ```
22
+
23
+ This might bring unwanted results for cases when strict comparison was wanted.
24
+
25
+ On the other hand, it gives more flexibility for many other cases, especially with isolated loader.
26
+ For example, this will work now, when it wasn't working before.
27
+
28
+ ```ruby
29
+ # ActiveRecord object
30
+ object = Entity.first
31
+
32
+ # Initialize isolated loader
33
+ instance = loader.new([object])
34
+
35
+ # This was working before because the loaded object is identical to passed object by `#object_id`
36
+ instance.for(object)
37
+
38
+ # This wasn't working before because the loaded object is not identical to passed one by `#object_id`
39
+ #
40
+ # But it will be working now, because object == Entity.find(object.id)
41
+ instance.for(Entity.find(object.id))
42
+ ```
43
+
44
+ If you need strict comparison support, please feel free to open the issue or the PR.
45
+
1
46
  ## [1.6.6] - 2023/07/30
2
47
 
3
48
  - Fix naive check of required arguments. Thanks [Nazar Matus](https://github.com/FunkyloverOne) for the issue!
@@ -4,7 +4,7 @@ module N1Loader
4
4
  module ActiveRecord
5
5
  module Associations
6
6
  module Preloader # :nodoc:
7
- N1LoaderReflection = Struct.new(:key, :loader) do
7
+ N1LoaderReflection = Struct.new(:name, :loader) do
8
8
  def options
9
9
  {}
10
10
  end
@@ -12,7 +12,7 @@ module N1Loader
12
12
 
13
13
  def preloaders_for_one(association, records, scope)
14
14
  grouped_records(association, records).flat_map do |reflection, klasses|
15
- next N1Loader::Preloader.new(records).preload(reflection.key) if reflection.is_a?(N1LoaderReflection)
15
+ next N1Loader::Preloader.new(records).preload(reflection.name) if reflection.is_a?(N1LoaderReflection)
16
16
 
17
17
  klasses.map do |rhs_klass, rs|
18
18
  loader = preloader_for(reflection, rs).new(rhs_klass, rs, reflection, scope)
@@ -4,7 +4,7 @@ module N1Loader
4
4
  module ActiveRecord
5
5
  module Associations
6
6
  module Preloader # :nodoc:
7
- N1LoaderReflection = Struct.new(:key, :loader) do
7
+ N1LoaderReflection = Struct.new(:name, :loader) do
8
8
  def options
9
9
  {}
10
10
  end
@@ -13,7 +13,7 @@ module N1Loader
13
13
  def preloaders_for_reflection(reflection, records, scope)
14
14
  return super unless reflection.is_a?(N1LoaderReflection)
15
15
 
16
- N1Loader::Preloader.new(records).preload(reflection.key)
16
+ N1Loader::Preloader.new(records).preload(reflection.name)
17
17
  end
18
18
 
19
19
  def grouped_records(association, records, polymorphic_parent)
@@ -4,7 +4,7 @@ module N1Loader
4
4
  module ActiveRecord
5
5
  module Associations
6
6
  module Preloader # :nodoc:
7
- N1LoaderReflection = Struct.new(:key, :loader) do
7
+ N1LoaderReflection = Struct.new(:name, :loader) do
8
8
  def options
9
9
  {}
10
10
  end
@@ -13,7 +13,7 @@ module N1Loader
13
13
  def preloaders_for_reflection(reflection, records)
14
14
  return super unless reflection.is_a?(N1LoaderReflection)
15
15
 
16
- N1Loader::Preloader.new(records).preload(reflection.key)
16
+ N1Loader::Preloader.new(records).preload(reflection.name)
17
17
  end
18
18
 
19
19
  def grouped_records # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
@@ -106,7 +106,7 @@ module N1Loader
106
106
 
107
107
  check_arguments!
108
108
 
109
- @loaded = {}.compare_by_identity
109
+ @loaded = {}
110
110
 
111
111
  if respond_to?(:single) && elements.size == 1
112
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.6"
4
+ VERSION = "1.7.1"
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.6
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin