deep_pluck 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +44 -17
- data/CHANGELOG.md +3 -0
- data/README.md +2 -2
- data/deep_pluck.gemspec +1 -1
- data/gemfiles/7.0.gemfile +14 -0
- data/lib/deep_pluck/data_combiner.rb +53 -40
- data/lib/deep_pluck/model.rb +4 -0
- data/lib/deep_pluck/version.rb +3 -1
- data/lib/deep_pluck.rb +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be904969a21ee38baa9e44b48a57be74b2b8b0a9189732d17a3e226afa75d13f
|
4
|
+
data.tar.gz: 92cc2e3650d2173d29ad048a417e46b3bb7cf93e39633a43ed247a4011fc7189
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50d4a7a590da8a8800bce18dd4228572b551916b060be591c6dcb1957b1bb676e583c240b07687f00207a74019be09bf81427e84904e39bfdc178cc156cb1bd0
|
7
|
+
data.tar.gz: 4aab9a20e9bed08be0537644e07e12844df6059b50dff0d4198609c53e95ae6305506df378aa7c103de2d5dbbb49021dd17f7576e934df2f332b89a8b9c216c2
|
data/.github/workflows/ruby.yml
CHANGED
@@ -20,9 +20,11 @@ jobs:
|
|
20
20
|
fail-fast: false
|
21
21
|
matrix:
|
22
22
|
ruby:
|
23
|
-
- 2.
|
23
|
+
- 2.3
|
24
24
|
- 2.6
|
25
25
|
- 2.7
|
26
|
+
- 3.0
|
27
|
+
- 3.1
|
26
28
|
gemfile:
|
27
29
|
- 3.2.gemfile
|
28
30
|
- 4.2.gemfile
|
@@ -31,32 +33,57 @@ jobs:
|
|
31
33
|
- 5.2.gemfile
|
32
34
|
- 6.0.gemfile
|
33
35
|
- 6.1.gemfile
|
36
|
+
- 7.0.gemfile
|
34
37
|
exclude:
|
35
38
|
- gemfile: 3.2.gemfile
|
36
39
|
ruby: 2.6
|
37
40
|
- gemfile: 3.2.gemfile
|
38
41
|
ruby: 2.7
|
42
|
+
- gemfile: 3.2.gemfile
|
43
|
+
ruby: 3.0
|
44
|
+
- gemfile: 3.2.gemfile
|
45
|
+
ruby: 3.1
|
39
46
|
- gemfile: 4.2.gemfile
|
40
47
|
ruby: 2.7
|
48
|
+
- gemfile: 4.2.gemfile
|
49
|
+
ruby: 3.0
|
50
|
+
- gemfile: 4.2.gemfile
|
51
|
+
ruby: 3.1
|
52
|
+
- gemfile: 5.0.gemfile
|
53
|
+
ruby: 3.0
|
54
|
+
- gemfile: 5.0.gemfile
|
55
|
+
ruby: 3.1
|
56
|
+
- gemfile: 5.1.gemfile
|
57
|
+
ruby: 3.0
|
58
|
+
- gemfile: 5.1.gemfile
|
59
|
+
ruby: 3.1
|
60
|
+
- gemfile: 5.2.gemfile
|
61
|
+
ruby: 3.0
|
62
|
+
- gemfile: 5.2.gemfile
|
63
|
+
ruby: 3.1
|
41
64
|
- gemfile: 6.0.gemfile
|
42
|
-
ruby: 2.
|
65
|
+
ruby: 2.3
|
43
66
|
- gemfile: 6.1.gemfile
|
44
|
-
ruby: 2.
|
67
|
+
ruby: 2.3
|
68
|
+
- gemfile: 7.0.gemfile
|
69
|
+
ruby: 2.3
|
70
|
+
- gemfile: 7.0.gemfile
|
71
|
+
ruby: 2.6
|
45
72
|
env:
|
46
73
|
BUNDLE_GEMFILE: "gemfiles/${{ matrix.gemfile }}"
|
47
74
|
|
48
75
|
steps:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
76
|
+
- name: Checkout
|
77
|
+
uses: actions/checkout@v2
|
78
|
+
- name: Setup Ruby
|
79
|
+
uses: ruby/setup-ruby@v1
|
80
|
+
with:
|
81
|
+
ruby-version: ${{ matrix.ruby }}
|
82
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
83
|
+
- name: Run tests
|
84
|
+
run: bundle exec rake
|
85
|
+
- name: Publish code coverage
|
86
|
+
if: ${{ success() }}
|
87
|
+
uses: paambaati/codeclimate-action@v2.7.5
|
88
|
+
env:
|
89
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### [v1.2.0](https://github.com/khiav223577/deep_pluck/compare/v1.1.7...v1.2.0) 2021/06/10
|
4
|
+
- [#50](https://github.com/khiav223577/deep_pluck/pull/50) Support `globalize` gem (@khiav223577)
|
5
|
+
|
3
6
|
### [v1.1.7](https://github.com/khiav223577/deep_pluck/compare/v1.1.6...v1.1.7) 2021/04/10
|
4
7
|
- [#48](https://github.com/khiav223577/deep_pluck/pull/48) Fix: joins incorrect table when doing inverse lookup for HABTM associations with custom name (@khiav223577)
|
5
8
|
- [#45](https://github.com/khiav223577/deep_pluck/pull/45) Do not publish code coverage for PRs from forks (@moon-moon-husky)
|
data/README.md
CHANGED
@@ -9,8 +9,8 @@
|
|
9
9
|
Allow you to pluck deeply into nested associations without loading a bunch of records.
|
10
10
|
|
11
11
|
## Supports
|
12
|
-
- Ruby 2.
|
13
|
-
- Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0
|
12
|
+
- Ruby 2.3 ~ 2.7, 3.0 ~ 3.1
|
13
|
+
- Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0, 7.0
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
data/deep_pluck.gemspec
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'zeitwerk'
|
4
|
+
gem 'activerecord', '~> 7.0.0'
|
5
|
+
gem 'pluck_all', '~> 2.3.2'
|
6
|
+
|
7
|
+
# gem 'globalize', '~> 6.0.1' # TODO: wait for globalize to support Rails 7.
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'simplecov', '< 0.18'
|
11
|
+
gem 'sqlite3', '~> 1.4.1'
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: '../'
|
@@ -1,40 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
model_hash[
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepPluck
|
4
|
+
module DataCombiner
|
5
|
+
class << self
|
6
|
+
def combine_data(parent, children, primary_key, column_name, foreign_key, reverse, collection)
|
7
|
+
source = reverse ? parent : children
|
8
|
+
target = !reverse ? parent : children
|
9
|
+
data_hash = make_data_hash(collection, source, primary_key, column_name, reverse)
|
10
|
+
assign_values_to_parent(collection, target, data_hash, column_name, foreign_key, reverse: reverse)
|
11
|
+
return children
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def make_data_hash(collection, parent, primary_key, column_name, reverse)
|
17
|
+
hash = {}
|
18
|
+
|
19
|
+
parent.each do |model_hash|
|
20
|
+
key = model_hash[primary_key]
|
21
|
+
|
22
|
+
if reverse
|
23
|
+
if collection
|
24
|
+
array = (hash[key] ? hash[key][column_name] : []) # share the children if id is duplicated
|
25
|
+
model_hash[column_name] = array # set the value of this association key to empty array by default
|
26
|
+
else
|
27
|
+
model_hash[column_name] = nil # set the value of this association key to be nil by default
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
hash[key] = model_hash
|
32
|
+
end
|
33
|
+
|
34
|
+
return hash
|
35
|
+
end
|
36
|
+
|
37
|
+
def assign_values_to_parent(collection, parent, children_hash, column_name, foreign_key, reverse: false)
|
38
|
+
parent.each do |data|
|
39
|
+
id = data[foreign_key]
|
40
|
+
|
41
|
+
left = reverse ? children_hash[id] : data
|
42
|
+
right = !reverse ? children_hash[id] : data
|
43
|
+
|
44
|
+
if collection
|
45
|
+
left[column_name] << right
|
46
|
+
else
|
47
|
+
left[column_name] = right
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/deep_pluck/model.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails_compatibility'
|
2
4
|
require 'rails_compatibility/unscope_where'
|
3
5
|
require 'rails_compatibility/build_joins'
|
@@ -50,6 +52,8 @@ module DeepPluck
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def get_primary_key(reflect)
|
55
|
+
options = reflect.options
|
56
|
+
return options[:primary_key] if options[:primary_key]
|
53
57
|
return (reflect.belongs_to? ? reflect.klass : reflect.active_record).primary_key
|
54
58
|
end
|
55
59
|
|
data/lib/deep_pluck/version.rb
CHANGED
data/lib/deep_pluck.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_pluck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,14 +106,14 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.0.
|
109
|
+
version: 0.0.8
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.0.
|
116
|
+
version: 0.0.8
|
117
117
|
description: 'Use deep_pluck as a shortcut to select one or more attributes and include
|
118
118
|
associated models without loading a bunch of records. And DRY up your code when
|
119
119
|
using #as_json.'
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- gemfiles/5.2.gemfile
|
143
143
|
- gemfiles/6.0.gemfile
|
144
144
|
- gemfiles/6.1.gemfile
|
145
|
+
- gemfiles/7.0.gemfile
|
145
146
|
- lib/deep_pluck.rb
|
146
147
|
- lib/deep_pluck/data_combiner.rb
|
147
148
|
- lib/deep_pluck/model.rb
|