eager_group 0.9.0 → 0.9.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: c8bad88cf4f0de57942e0477ee107ce8f40eeeded25b37def08ef560907ef143
4
- data.tar.gz: f14470d5456dbce04be8fac648623fbc0e1dbb25a3e89af5ebe7bde9dd6a61d5
3
+ metadata.gz: 119ff48ee90c0324a8e7f55e521a3606485ad1728ec27eaefea3df1f7c153173
4
+ data.tar.gz: 7415661b2a4ced20c7673c8d90bfb977fbef22c203062f0bb60a8be5fdd1970a
5
5
  SHA512:
6
- metadata.gz: 6e026cf0d9f8a9839b498b995ba7d48ab24afe2dc48f3e7d41cba16069ac4bc9b3c15d202e7b9730859aa81f24c8cb77a9e2bc8572e720a58457cc7f89f171a0
7
- data.tar.gz: 0033033e6b427479d0a49c2e2e1b1149f40a63a46f12aa42aa49f54fb91b27f84ee045aa96014c37b745fbad9b5ca84fab20b014ef521e478cbce058f681f803
6
+ metadata.gz: f3b85835d577315809f1a699c7a717d17b1f61c14ae0e0371312c12615a5088c45a266028fc3f091801639298e9dd6a1ca1e8d6beb37889a6f5e63aacbdc8fe6
7
+ data.tar.gz: 2475f41755b2b0161bcc4fe01fd04a5cb1b9f69728edd0e165e8596773306e421426efc191aa34eba812912c1e6b8cc608386a3fc29ca490a068c15b2335e337
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Next Release
2
2
 
3
+ ## 0.9.1 (12/15/2022)
4
+
5
+ * Fix eager group fetch multi definitions
6
+
3
7
  ## 0.9.0 (12/04/2022)
4
8
 
5
9
  * Support `has_many` through `belongs_to`
@@ -9,7 +9,10 @@ module ActiveRecord
9
9
  end
10
10
 
11
11
  def eager_group(*args)
12
- check_if_method_has_arguments!(__callee__, args)
12
+ # we does not use the `check_if_method_has_arguments!` here because it would flatten all the arguments,
13
+ # which would cause `[:eager_group_definition, scope_arg1, scope_arg2]` not able to preload together with other `eager_group_definitions`.
14
+ # e.g. `Post.eager_group(:approved_comments_count, [:comments_average_rating_by_author, students[0], true])`
15
+ check_argument_not_blank!(args)
13
16
 
14
17
  spawn.eager_group!(*args)
15
18
  end
@@ -28,5 +31,12 @@ module ActiveRecord
28
31
 
29
32
  @values[:eager_group] = values
30
33
  end
34
+
35
+ private
36
+
37
+ def check_argument_not_blank!(args)
38
+ raise ArgumentError, "The method .eager_group() must contain arguments." if args.blank?
39
+ args.compact_blank!
40
+ end
31
41
  end
32
42
  end
@@ -25,6 +25,10 @@ module EagerGroup
25
25
  @klass.primary_key
26
26
  end
27
27
 
28
+ def aggregate_hash
29
+ raise NotImplementedError, 'Method "aggregate_hash" must be implemented in subclass'
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def polymophic_as_condition
@@ -11,8 +11,7 @@ module EagerGroup
11
11
  def initialize(klass, records, eager_group_values)
12
12
  @klass = klass
13
13
  @records = Array.wrap(records).compact.uniq
14
- eager_group_definitions = @klass.eager_group_definitions
15
- @eager_group_values = eager_group_values.all? { |value| eager_group_definitions.key?(value) } ? eager_group_values : [eager_group_values]
14
+ @eager_group_values = eager_group_values
16
15
  end
17
16
 
18
17
  # Preload aggregate functions
@@ -27,11 +26,10 @@ module EagerGroup
27
26
  next if @records.empty?
28
27
 
29
28
  @klass = @records.first.class
29
+ self.class.new(@klass, @records, Array.wrap(definition_key)).run
30
30
  end
31
31
 
32
- Array.wrap(definition_key).each do |key|
33
- find_aggregate_values_per_definition!(key, arguments)
34
- end
32
+ find_aggregate_values_per_definition!(definition_key, arguments)
35
33
  end
36
34
  end
37
35
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EagerGroup
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
  end
data/lib/eager_group.rb CHANGED
@@ -40,7 +40,7 @@ module EagerGroup
40
40
  private
41
41
 
42
42
  def preload_eager_group(*eager_group_value)
43
- EagerGroup::Preloader.new(self.class, [self], eager_group_value).run
43
+ EagerGroup::Preloader.new(self.class, [self], [eager_group_value]).run
44
44
  end
45
45
  end
46
46
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eager_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-04 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord