eager_group 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +5 -5
- data/eager_group.gemspec +1 -0
- data/lib/eager_group.rb +3 -3
- data/lib/eager_group/definition.rb +1 -0
- data/lib/eager_group/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 559e8eeb3768f38a63b7ec19a0201dfc583073e37cc145ffabd19886bfe4ba59
|
4
|
+
data.tar.gz: 72fa7fd007ac0f9de02490cde602b25ad6bbb3ef48b8d61b1b13976721d89fcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39e828e5c8e1315d2a3083907c172373c7f6026d3397a7f0eecbf6722408e87af71c3c22226e271d7a7369806227184513a68df24cf865d2dcf6ea8e23f63652
|
7
|
+
data.tar.gz: 559307e3dac7da634ed9a3e28d93a7dbf0f2b16eb422887f308bfd01f1241806485ce34b62a3d6c66fe9a601f63128fe14a2ce47f729c92508516bd60e637e3d
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# Next Release
|
2
2
|
|
3
|
-
## 0.7.
|
3
|
+
## 0.7.1 (08/23/2019)
|
4
4
|
|
5
|
-
*
|
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
|
92
|
-
|
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
|
142
|
-
association
|
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
|
data/eager_group.gemspec
CHANGED
@@ -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'
|
data/lib/eager_group.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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}")
|
data/lib/eager_group/version.rb
CHANGED
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.
|
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-
|
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
|