eager_group 0.7.0 → 0.7.1

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: 7ee556b1563f43bb0b0b19d07b47cadf828a0a06586687bb23cea618c85f4d4f
4
- data.tar.gz: 67f6b99dae67ae911a02261c98d662fa465407579b4962132d7b7d024bed9816
3
+ metadata.gz: 559e8eeb3768f38a63b7ec19a0201dfc583073e37cc145ffabd19886bfe4ba59
4
+ data.tar.gz: 72fa7fd007ac0f9de02490cde602b25ad6bbb3ef48b8d61b1b13976721d89fcf
5
5
  SHA512:
6
- metadata.gz: 912675975d5fab05a06045bc387ac1c128f2c313c692fc60f5df925d04bb7d846d9d1a458cc64c6a2c6139fc77e7d7c0721bf4173c3d115922ad2ffecff047e0
7
- data.tar.gz: ce554fd38a31348d7fee55472aaefcf559a88db0f33f24a516273a83d7380079594377a33ff5d625802329496fc50d8f611006dc4b2bf3fabf00eaef8d26e835
6
+ metadata.gz: 39e828e5c8e1315d2a3083907c172373c7f6026d3397a7f0eecbf6722408e87af71c3c22226e271d7a7369806227184513a68df24cf865d2dcf6ea8e23f63652
7
+ data.tar.gz: 559307e3dac7da634ed9a3e28d93a7dbf0f2b16eb422887f308bfd01f1241806485ce34b62a3d6c66fe9a601f63128fe14a2ce47f729c92508516bd60e637e3d
@@ -1,8 +1,12 @@
1
1
  # Next Release
2
2
 
3
- ## 0.7.0 (03/05/2018)
3
+ ## 0.7.1 (08/23/2019)
4
4
 
5
- * Add first_object and last_object aggregation
5
+ * Set `eager_group_definitions` by `mattr_accessor`
6
+
7
+ ## 0.7.0 (08/22/2019)
8
+
9
+ * Add `first_object` and `last_object` aggregation
6
10
 
7
11
  ## 0.6.1 (03/05/2018)
8
12
 
data/README.md CHANGED
@@ -88,8 +88,8 @@ result.
88
88
  * `association`, association name you want to aggregate.
89
89
  * `aggregate_function`, aggregate sql function, can be one of `average`,
90
90
  `count`, `maximum`, `minimum`, `sum`, I define 2 additional aggregate
91
- function `first_object` and `last_object` to fetch first and last object
92
- from associations.
91
+ function `first_object` and `last_object` to eager load first and last
92
+ association objects.
93
93
  * `column_name`, aggregate column name, it can be `:*` for `count`
94
94
  * `scope`, scope is optional, it's used to filter data for aggregation.
95
95
 
@@ -119,7 +119,7 @@ post.approved_comments_count
119
119
 
120
120
  ## Advanced
121
121
 
122
- eager_group through association
122
+ `eager_group` through association
123
123
 
124
124
  ```ruby
125
125
  User.limit(10).includes(:posts).eager_group(posts: [:comments_average_rating, :approved_comments_count])
@@ -138,8 +138,8 @@ posts = Post.all.eager_group([:comments_average_rating_by_author, author, true])
138
138
  posts.each { |post| post.comments_average_rating_by_author }
139
139
  ```
140
140
 
141
- first_object and last_object aggregation to fetch first and last
142
- association object.
141
+ `first_object` and `last_object` aggregation to eager load first and
142
+ last association objects.
143
143
 
144
144
  ```ruby
145
145
  class Post < ActiveRecord::Base
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'activerecord'
25
25
  spec.add_development_dependency 'activerecord-import'
26
+ spec.add_development_dependency 'activesupport'
26
27
  spec.add_development_dependency 'benchmark-ips'
27
28
  spec.add_development_dependency 'bundler'
28
29
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/module/attribute_accessors'
3
4
  require 'eager_group/version'
4
5
 
5
6
  module EagerGroup
@@ -11,7 +12,7 @@ module EagerGroup
11
12
  end
12
13
 
13
14
  module ClassMethods
14
- attr_reader :eager_group_definitions
15
+ mattr_accessor :eager_group_definitions, default: {}
15
16
 
16
17
  # class Post
17
18
  # define_eager_group :comments_avergage_rating, :comments, :average, :rating
@@ -19,8 +20,7 @@ module EagerGroup
19
20
  # end
20
21
  def define_eager_group(attr, association, aggregate_function, column_name, scope = nil)
21
22
  send :attr_accessor, attr
22
- @eager_group_definitions ||= {}
23
- @eager_group_definitions[attr] = Definition.new association, aggregate_function, column_name, scope
23
+ self.eager_group_definitions[attr] = Definition.new(association, aggregate_function, column_name, scope)
24
24
 
25
25
  define_method attr, lambda { |*args|
26
26
  query_result_cache = instance_variable_get("@#{attr}")
@@ -14,6 +14,7 @@ module EagerGroup
14
14
  def aggregation_function
15
15
  return :maximum if @aggregate_function.to_sym == :last_object
16
16
  return :minimum if @aggregate_function.to_sym == :first_object
17
+
17
18
  @aggregate_function
18
19
  end
19
20
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EagerGroup
4
- VERSION = '0.7.0'
4
+ VERSION = '0.7.1'
5
5
  end
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.7.0
4
+ version: 0.7.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: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: benchmark-ips
43
57
  requirement: !ruby/object:Gem::Requirement