pluck_all 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,70 +1,73 @@
1
- ## Change Log
2
-
3
- ### [v2.1.0](https://github.com/khiav223577/pluck_all/compare/v2.0.4...v2.1.0) 2020/10/19
4
- - [#47](https://github.com/khiav223577/pluck_all/pull/47) Use instantiate method to initialize model without calling callbacks (@khiav223577)
5
- - [#45](https://github.com/khiav223577/pluck_all/pull/45) Support Ruby 2.7 (@khiav223577)
6
- - [#44](https://github.com/khiav223577/pluck_all/pull/44) Move `require` from begin..rescue block for better debug message (@khiav223577)
7
- - [#43](https://github.com/khiav223577/pluck_all/pull/43) Use rails_compatibility to get attribute_types for better compatibility (@khiav223577)
8
- - [#41](https://github.com/khiav223577/pluck_all/pull/41) Support Rails 6.0 (@khiav223577)
9
-
10
- ### [v2.0.4](https://github.com/khiav223577/pluck_all/compare/v2.0.3...v2.0.4) 2019/04/04
11
- - [#40](https://github.com/khiav223577/pluck_all/pull/40) Fix: inconsistent with pluck when having `select` on relation (@khiav223577)
12
- - [#39](https://github.com/khiav223577/pluck_all/pull/39) Fix: undefined local variable or method `construct_relation_for_association_calculations` in Rails 5.2.2.1 (@MasashiYokota)
13
- - [#36](https://github.com/khiav223577/pluck_all/pull/36) Fix: broken test cases after bundler 2.0 was released (@khiav223577)
14
- - [#35](https://github.com/khiav223577/pluck_all/pull/35) refactor #test_pluck_with_includes (@khiav223577)
15
- - [#34](https://github.com/khiav223577/pluck_all/pull/34) Provide Arel support as well (@snkashis)
16
- - [#33](https://github.com/khiav223577/pluck_all/pull/33) Fix gemfile path in bin/setup (@snkashis)
17
- - [#32](https://github.com/khiav223577/pluck_all/pull/32) Move patches into separate files (@khiav223577)
18
-
19
- ### [v2.0.3](https://github.com/khiav223577/pluck_all/compare/v2.0.2...v2.0.3) 2018/07/19
20
- - [#30](https://github.com/khiav223577/pluck_all/pull/30) Fix: includes + pluck_all results in strange output (@khiav223577)
21
-
22
- ### [v2.0.2](https://github.com/khiav223577/pluck_all/compare/v2.0.1...v2.0.2) 2018/06/29
23
- - [#28](https://github.com/khiav223577/pluck_all/pull/28) Fix test cases and the result format may be wrong when plucking multiple columns with nil value may (@khiav223577)
24
- - [#27](https://github.com/khiav223577/pluck_all/pull/27) [Feature] Mongoid Hooks And Tests Separation (@berniechiu)
25
- - [#26](https://github.com/khiav223577/pluck_all/pull/26) [FIX] Wrong Module Skipped (@berniechiu)
26
-
27
- ### [v2.0.1](https://github.com/khiav223577/pluck_all/compare/v2.0.0...v2.0.1) 2018/05/27
28
- - [#25](https://github.com/khiav223577/pluck_all/pull/25) Fix that project without mongoid will raise LoadError (@khiav223577)
29
-
30
- ### [v2.0.0](https://github.com/khiav223577/pluck_all/compare/v1.2.4...v2.0.0) 2018/05/27
31
- - [#24](https://github.com/khiav223577/pluck_all/pull/24) Support Mongoid! (@khiav223577)
32
- - [#23](https://github.com/khiav223577/pluck_all/pull/23) Refactoring Coding Style (@khiav223577)
33
- - [#22](https://github.com/khiav223577/pluck_all/pull/22) test Rails 5.2 (@khiav223577)
34
- - [#21](https://github.com/khiav223577/pluck_all/pull/21) should test both 5.0.x and 5.1.x (@khiav223577)
35
- - [#20](https://github.com/khiav223577/pluck_all/pull/20) test pluck_all in rails 5.1.x (@khiav223577)
36
- - [#19](https://github.com/khiav223577/pluck_all/pull/19) add test cases to test `join` with table name and `alias` (@khiav223577)
37
-
38
- ### [v1.2.4](https://github.com/khiav223577/pluck_all/compare/v1.2.3...v1.2.4) 2017/04/11
39
- - [#17](https://github.com/khiav223577/pluck_all/pull/17) supports carrierwave 1.0.0 (@khiav223577)
40
-
41
- ### [v1.2.3](https://github.com/khiav223577/pluck_all/compare/v1.2.2...v1.2.3) 2017/04/03
42
- - [#14](https://github.com/khiav223577/pluck_all/pull/14) use mass assign to assign values (@khiav223577)
43
- - [#16](https://github.com/khiav223577/pluck_all/pull/16) Checking if Class has CarrierWave loaded (@basex)
44
- - [#15](https://github.com/khiav223577/pluck_all/pull/15) Restrict dependency to activerecord (@basex)
45
-
46
- ### [v1.2.2](https://github.com/khiav223577/pluck_all/compare/v1.2.1...v1.2.2) 2017/03/14
47
- - [#13](https://github.com/khiav223577/pluck_all/pull/13) Model.none.pluck_all(..) should return empty array instead of raising exception (@khiav223577)
48
- - [#12](https://github.com/khiav223577/pluck_all/pull/12) test other ruby version (@khiav223577)
49
-
50
- ### [v1.2.1](https://github.com/khiav223577/pluck_all/compare/v1.2.0...v1.2.1) 2017/01/24
51
- - [#11](https://github.com/khiav223577/pluck_all/pull/11) always return carrierwave uploader if possible (@khiav223577)
52
- - [#10](https://github.com/khiav223577/pluck_all/pull/10) change pluck_all return value of carrierwave column (@khiav223577)
53
-
54
- ### [v1.2.0](https://github.com/khiav223577/pluck_all/compare/v1.1.2...v1.2.0) 2017/01/24
55
- - [#5](https://github.com/khiav223577/pluck_all/pull/5) Support casting CarrierWave url (@khiav223577)
56
- - [#9](https://github.com/khiav223577/pluck_all/pull/9) need ActiveRecord version not Rails version (@khiav223577)
57
- - [#8](https://github.com/khiav223577/pluck_all/pull/8) Upgrade rake version in development (@khiav223577)
58
-
59
- ### [v1.1.2](https://github.com/khiav223577/pluck_all/compare/v1.1.1...v1.1.2) 2017/01/06
60
- - [#7](https://github.com/khiav223577/pluck_all/pull/7) fix pluck_all with join (@khiav223577)
61
-
62
- ### [v1.1.1](https://github.com/khiav223577/pluck_all/compare/v1.1.0...v1.1.1) 2017/01/01
63
- - [#4](https://github.com/khiav223577/pluck_all/pull/4) add code climate (@khiav223577)
64
-
65
- ### [v1.1.0](https://github.com/khiav223577/pluck_all/compare/v1.0.1...v1.1.0) 2016/12/21
66
- - [#3](https://github.com/khiav223577/pluck_all/pull/3) Feature/pluck array (@khiav223577)
67
-
68
- ### [v1.0.1](https://github.com/khiav223577/pluck_all/compare/v1.0.0...v1.0.1) 2016/12/20
69
- - [#2](https://github.com/khiav223577/pluck_all/pull/2) test with multiple rails version (@khiav223577)
70
- - [#1](https://github.com/khiav223577/pluck_all/pull/1) add basic test cases (@khiav223577)
1
+ ## Change Log
2
+
3
+ ### [v2.2.1](https://github.com/khiav223577/pluck_all/compare/v2.1.0...v2.2.1) 2020/12/29
4
+ - [#48](https://github.com/khiav223577/pluck_all/pull/48) fix Rails 6.1 `map!` deprecation warning (@klausbadelt)
5
+
6
+ ### [v2.1.0](https://github.com/khiav223577/pluck_all/compare/v2.0.4...v2.1.0) 2020/10/19
7
+ - [#47](https://github.com/khiav223577/pluck_all/pull/47) Use instantiate method to initialize model without calling callbacks (@khiav223577)
8
+ - [#45](https://github.com/khiav223577/pluck_all/pull/45) Support Ruby 2.7 (@khiav223577)
9
+ - [#44](https://github.com/khiav223577/pluck_all/pull/44) Move `require` from begin..rescue block for better debug message (@khiav223577)
10
+ - [#43](https://github.com/khiav223577/pluck_all/pull/43) Use rails_compatibility to get attribute_types for better compatibility (@khiav223577)
11
+ - [#41](https://github.com/khiav223577/pluck_all/pull/41) Support Rails 6.0 (@khiav223577)
12
+
13
+ ### [v2.0.4](https://github.com/khiav223577/pluck_all/compare/v2.0.3...v2.0.4) 2019/04/04
14
+ - [#40](https://github.com/khiav223577/pluck_all/pull/40) Fix: inconsistent with pluck when having `select` on relation (@khiav223577)
15
+ - [#39](https://github.com/khiav223577/pluck_all/pull/39) Fix: undefined local variable or method `construct_relation_for_association_calculations` in Rails 5.2.2.1 (@MasashiYokota)
16
+ - [#36](https://github.com/khiav223577/pluck_all/pull/36) Fix: broken test cases after bundler 2.0 was released (@khiav223577)
17
+ - [#35](https://github.com/khiav223577/pluck_all/pull/35) refactor #test_pluck_with_includes (@khiav223577)
18
+ - [#34](https://github.com/khiav223577/pluck_all/pull/34) Provide Arel support as well (@snkashis)
19
+ - [#33](https://github.com/khiav223577/pluck_all/pull/33) Fix gemfile path in bin/setup (@snkashis)
20
+ - [#32](https://github.com/khiav223577/pluck_all/pull/32) Move patches into separate files (@khiav223577)
21
+
22
+ ### [v2.0.3](https://github.com/khiav223577/pluck_all/compare/v2.0.2...v2.0.3) 2018/07/19
23
+ - [#30](https://github.com/khiav223577/pluck_all/pull/30) Fix: includes + pluck_all results in strange output (@khiav223577)
24
+
25
+ ### [v2.0.2](https://github.com/khiav223577/pluck_all/compare/v2.0.1...v2.0.2) 2018/06/29
26
+ - [#28](https://github.com/khiav223577/pluck_all/pull/28) Fix test cases and the result format may be wrong when plucking multiple columns with nil value may (@khiav223577)
27
+ - [#27](https://github.com/khiav223577/pluck_all/pull/27) [Feature] Mongoid Hooks And Tests Separation (@berniechiu)
28
+ - [#26](https://github.com/khiav223577/pluck_all/pull/26) [FIX] Wrong Module Skipped (@berniechiu)
29
+
30
+ ### [v2.0.1](https://github.com/khiav223577/pluck_all/compare/v2.0.0...v2.0.1) 2018/05/27
31
+ - [#25](https://github.com/khiav223577/pluck_all/pull/25) Fix that project without mongoid will raise LoadError (@khiav223577)
32
+
33
+ ### [v2.0.0](https://github.com/khiav223577/pluck_all/compare/v1.2.4...v2.0.0) 2018/05/27
34
+ - [#24](https://github.com/khiav223577/pluck_all/pull/24) Support Mongoid! (@khiav223577)
35
+ - [#23](https://github.com/khiav223577/pluck_all/pull/23) Refactoring Coding Style (@khiav223577)
36
+ - [#22](https://github.com/khiav223577/pluck_all/pull/22) test Rails 5.2 (@khiav223577)
37
+ - [#21](https://github.com/khiav223577/pluck_all/pull/21) should test both 5.0.x and 5.1.x (@khiav223577)
38
+ - [#20](https://github.com/khiav223577/pluck_all/pull/20) test pluck_all in rails 5.1.x (@khiav223577)
39
+ - [#19](https://github.com/khiav223577/pluck_all/pull/19) add test cases to test `join` with table name and `alias` (@khiav223577)
40
+
41
+ ### [v1.2.4](https://github.com/khiav223577/pluck_all/compare/v1.2.3...v1.2.4) 2017/04/11
42
+ - [#17](https://github.com/khiav223577/pluck_all/pull/17) supports carrierwave 1.0.0 (@khiav223577)
43
+
44
+ ### [v1.2.3](https://github.com/khiav223577/pluck_all/compare/v1.2.2...v1.2.3) 2017/04/03
45
+ - [#14](https://github.com/khiav223577/pluck_all/pull/14) use mass assign to assign values (@khiav223577)
46
+ - [#16](https://github.com/khiav223577/pluck_all/pull/16) Checking if Class has CarrierWave loaded (@basex)
47
+ - [#15](https://github.com/khiav223577/pluck_all/pull/15) Restrict dependency to activerecord (@basex)
48
+
49
+ ### [v1.2.2](https://github.com/khiav223577/pluck_all/compare/v1.2.1...v1.2.2) 2017/03/14
50
+ - [#13](https://github.com/khiav223577/pluck_all/pull/13) Model.none.pluck_all(..) should return empty array instead of raising exception (@khiav223577)
51
+ - [#12](https://github.com/khiav223577/pluck_all/pull/12) test other ruby version (@khiav223577)
52
+
53
+ ### [v1.2.1](https://github.com/khiav223577/pluck_all/compare/v1.2.0...v1.2.1) 2017/01/24
54
+ - [#11](https://github.com/khiav223577/pluck_all/pull/11) always return carrierwave uploader if possible (@khiav223577)
55
+ - [#10](https://github.com/khiav223577/pluck_all/pull/10) change pluck_all return value of carrierwave column (@khiav223577)
56
+
57
+ ### [v1.2.0](https://github.com/khiav223577/pluck_all/compare/v1.1.2...v1.2.0) 2017/01/24
58
+ - [#5](https://github.com/khiav223577/pluck_all/pull/5) Support casting CarrierWave url (@khiav223577)
59
+ - [#9](https://github.com/khiav223577/pluck_all/pull/9) need ActiveRecord version not Rails version (@khiav223577)
60
+ - [#8](https://github.com/khiav223577/pluck_all/pull/8) Upgrade rake version in development (@khiav223577)
61
+
62
+ ### [v1.1.2](https://github.com/khiav223577/pluck_all/compare/v1.1.1...v1.1.2) 2017/01/06
63
+ - [#7](https://github.com/khiav223577/pluck_all/pull/7) fix pluck_all with join (@khiav223577)
64
+
65
+ ### [v1.1.1](https://github.com/khiav223577/pluck_all/compare/v1.1.0...v1.1.1) 2017/01/01
66
+ - [#4](https://github.com/khiav223577/pluck_all/pull/4) add code climate (@khiav223577)
67
+
68
+ ### [v1.1.0](https://github.com/khiav223577/pluck_all/compare/v1.0.1...v1.1.0) 2016/12/21
69
+ - [#3](https://github.com/khiav223577/pluck_all/pull/3) Feature/pluck array (@khiav223577)
70
+
71
+ ### [v1.0.1](https://github.com/khiav223577/pluck_all/compare/v1.0.0...v1.0.1) 2016/12/20
72
+ - [#2](https://github.com/khiav223577/pluck_all/pull/2) test with multiple rails version (@khiav223577)
73
+ - [#1](https://github.com/khiav223577/pluck_all/pull/1) add basic test cases (@khiav223577)
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,49 +1,49 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
7
-
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
12
-
13
- Examples of unacceptable behavior by participants include:
14
-
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
18
- * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
22
-
23
- Project maintainers have the right and responsibility to remove, edit, or
24
- reject comments, commits, code, wiki edits, issues, and other contributions
25
- that are not aligned to this Code of Conduct, or to ban temporarily or
26
- permanently any contributor for other behaviors that they deem inappropriate,
27
- threatening, offensive, or harmful.
28
-
29
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
33
-
34
- This code of conduct applies both within project spaces and in public spaces
35
- when an individual is representing the project or its community.
36
-
37
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
39
- complaints will be reviewed and investigated and will result in a response that
40
- is deemed necessary and appropriate to the circumstances. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
43
-
44
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
- version 1.3.0, available at
46
- [http://contributor-covenant.org/version/1/3/0/][version]
47
-
48
- [homepage]: http://contributor-covenant.org
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
49
  [version]: http://contributor-covenant.org/version/1/3/0/
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 khiav reoy
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 khiav reoy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,167 +1,187 @@
1
- # PluckAll
2
-
3
- [![Gem Version](https://img.shields.io/gem/v/pluck_all.svg?style=flat)](http://rubygems.org/gems/pluck_all)
4
- [![Build Status](https://travis-ci.org/khiav223577/pluck_all.svg?branch=master)](https://travis-ci.org/khiav223577/pluck_all)
5
- [![RubyGems](http://img.shields.io/gem/dt/pluck_all.svg?style=flat)](http://rubygems.org/gems/pluck_all)
6
- [![Code Climate](https://codeclimate.com/github/khiav223577/pluck_all/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/pluck_all)
7
- [![Test Coverage](https://codeclimate.com/github/khiav223577/pluck_all/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/pluck_all/coverage)
8
-
9
- Pluck multiple columns/attributes in Rails 3, 4, 5, 6, and can return data as hash instead of only array. Also supports `Mongoid`.
10
-
11
- This Gem stands on the shoulders of this article: [Plucking Multiple Columns in Rails 3](https://meltingice.dev/2013/06/11/pluck-multiple-columns-rails/).
12
- And modified to support not only Rail 3.
13
-
14
- If you have a Rails 3 project, and want to pluck not only one column,
15
- feel free to use this gem and no need to worry about upgrading to Rails 4, 5, 6 in the future will break this.
16
-
17
- ## Supports
18
- - Ruby 2.2 ~ 2.7
19
- - Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0, 6.1
20
-
21
- ## Installation
22
-
23
- Add this line to your application's Gemfile:
24
-
25
- ```ruby
26
- gem 'pluck_all'
27
- ```
28
-
29
- And then execute:
30
-
31
- $ bundle
32
-
33
- Or install it yourself as:
34
-
35
- $ gem install pluck_all
36
-
37
- ## Usage
38
-
39
- ### pluck to array
40
-
41
- Behaves the same as `#pluck` method, but you can use it to pluck multiple columns in Rails 3
42
-
43
- ```rb
44
- User.where('id < 3').pluck_array(:id, :account)
45
- # => [[1, 'account1'], [2, 'account2']]
46
- ```
47
-
48
- ### pluck to hash
49
-
50
- Similar to `#pluck` method, but return array of hashes instead.
51
-
52
- ```rb
53
- User.where('id < 3').pluck_all(:id, :account)
54
- # => [{"id"=>1, "account"=>"account1"}, {"id"=>2, "account"=>"account2"}]
55
-
56
- User.where('id < 3').pluck_all(:id, 'account AS name')
57
- # => [{"id"=>1, "name"=>"account1"}, {"id"=>2, "name"=>"account2"}]
58
-
59
- User.where('id < 3').pluck_all('id, account AS name')
60
- # => [{"id"=>1, "name"=>"account1"}, {"id"=>2, "name"=>"account2"}]
61
- ```
62
-
63
- ## Support Mongoid
64
- ```rb
65
- class User
66
- include Mongoid::Document
67
-
68
- field :name, type: String
69
- field :age, type: Integer
70
- end
71
-
72
- User.pluck_all(:name, :age)
73
- # => [
74
- # {'name' => 'Pearl Shi' , 'age' => 18},
75
- # {'name' => 'Rumble Huang', 'age' => 20},
76
- # {'name' => 'Khiav Reoy' , 'age' => 20},
77
- # ]
78
- ```
79
-
80
-
81
- ## Benchmark
82
- ### Compare with `map` and `as_json`
83
-
84
- `pluck_all` return raw `hash` data without loading a bunch of records, in that having better performace than using `map` and `as_json`. The following is the benchmark test on 191,093 users, where `users` table have 51 columns.
85
-
86
- ```rb
87
- user system total real
88
- map 36.110000 61.200000 97.310000 ( 99.535375)
89
- select + map 10.530000 0.660000 11.190000 ( 12.550974)
90
- select + as_json 49.040000 1.120000 50.160000 ( 55.417534)
91
- pluck_all 3.310000 0.100000 3.410000 ( 3.527775)
92
- ```
93
- Test by `benchmark-ips` and `limit 100` in each iteration:
94
- ```
95
- Warming up --------------------------------------
96
- map 1.000 i/100ms
97
- select + map 28.000 i/100ms
98
- select + as_json 7.000 i/100ms
99
- pluck_all 54.000 i/100ms
100
- Calculating -------------------------------------
101
- map 14.230 (± 0.0%) i/s - 72.000 in 5.065349s
102
- select + map 281.638 (± 4.6%) i/s - 1.428k in 5.081216s
103
- select + as_json 73.241 (± 4.1%) i/s - 371.000 in 5.076235s
104
- pluck_all 539.057 (± 6.7%) i/s - 2.700k in 5.034858s
105
-
106
- Comparison:
107
- pluck_all: 539.1 i/s
108
- select + map: 281.6 i/s - 1.91x slower
109
- select + as_json: 73.2 i/s - 7.36x slower
110
- map: 14.2 i/s - 37.88x slower
111
- ```
112
- [test script](https://github.com/khiav223577/pluck_all/issues/18)
113
-
114
- ### Compare with [pluck_to_hash](https://github.com/girishso/pluck_to_hash) gem
115
-
116
- `pluck_all` has better performace since it uses raw `hash` data from `ActiveRecord::Base.connection.select_all`, while `pluck_to_hash` uses `pluck` method, which calls `ActiveRecord::Base.connection.select_all` and transfers the raw `hash` data to `array` format, and then transfer the data to `hash` format again. The following benchmark shows the performance difference:
117
-
118
- ```rb
119
-                                       user     system     total       real
120
- pluck_to_hash 2.960000 0.130000 3.090000 ( 3.421640)
121
- pluck_all 2.160000 0.120000 2.280000 ( 2.605118)
122
- ```
123
- Tested by `benchmark-ips` and `limit 1000` in each iteration:
124
- ```
125
- Warming up --------------------------------------
126
- pluck_to_hash 7.000 i/100ms
127
- pluck_all 9.000 i/100ms
128
- Calculating -------------------------------------
129
- pluck_to_hash 84.526 (± 4.7%) i/s - 427.000 in 5.065792s
130
- pluck_all 95.133 (± 4.2%) i/s - 477.000 in 5.021555s
131
-
132
- Comparison:
133
- pluck_all: 95.1 i/s
134
- pluck_to_hash: 84.5 i/s - 1.13x slower
135
- ```
136
- See the [test script](https://github.com/khiav223577/pluck_all/issues/18#issuecomment-325407080) for more details.
137
-
138
- ## Other Support
139
- ### Support Pluck Carrierwave Uploader (if you use carrierwave)
140
- ```rb
141
- User.where(xxx).pluck_all(:profile_pic).map{|s| s['profile_pic'] }
142
- ```
143
- is the same as
144
- ```rb
145
- User.where(xxx).map(&:profile_pic)
146
- ```
147
- If the uploader use something like: `model.id`, `model.name`
148
- You may have to send these columns manually:
149
- ```rb
150
- User.where(xxx).cast_need_columns(%i[id name]).pluck_all(:id, :name, :profile_pic).map{|s| s['profile_pic'] }
151
- ```
152
-
153
- ## Development
154
-
155
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test_active_record` or `rake test_mongoid` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
156
-
157
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
158
-
159
- ## Contributing
160
-
161
- Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/pluck_all. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
162
-
163
-
164
- ## License
165
-
166
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
167
-
1
+ # PluckAll
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/pluck_all.svg?style=flat)](http://rubygems.org/gems/pluck_all)
4
+ [![Build Status](https://github.com/khiav223577/pluck_all/workflows/Ruby/badge.svg)](https://github.com/khiav223577/pluck_all/actions)
5
+ [![RubyGems](http://img.shields.io/gem/dt/pluck_all.svg?style=flat)](http://rubygems.org/gems/pluck_all)
6
+ [![Code Climate](https://codeclimate.com/github/khiav223577/pluck_all/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/pluck_all)
7
+ [![Test Coverage](https://codeclimate.com/github/khiav223577/pluck_all/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/pluck_all/coverage)
8
+
9
+ Pluck multiple columns/attributes in Rails 3, 4, 5, 6, and can return data as hash instead of only array. Also supports `Mongoid`.
10
+
11
+ This Gem stands on the shoulders of this article: [Plucking Multiple Columns in Rails 3](https://meltingice.dev/2013/06/11/pluck-multiple-columns-rails/).
12
+ And modified to support not only Rail 3.
13
+
14
+ If you have a Rails 3 project, and want to pluck not only one column,
15
+ feel free to use this gem and no need to worry about upgrading to Rails 4, 5, 6 in the future will break this.
16
+
17
+ ## Supports
18
+ - Ruby 2.2 ~ 2.7
19
+ - Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0, 6.1
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'pluck_all'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install pluck_all
36
+
37
+ ## Usage
38
+
39
+ ### pluck to array
40
+
41
+ Behaves the same as `#pluck` method, but you can use it to pluck multiple columns in Rails 3
42
+
43
+ ```rb
44
+ User.where('id < 3').pluck_array(:id, :account)
45
+ # => [[1, 'account1'], [2, 'account2']]
46
+ ```
47
+
48
+ ### pluck to hash
49
+
50
+ Similar to `#pluck` method, but return array of hashes instead.
51
+
52
+ ```rb
53
+ User.where('id < 3').pluck_all(:id, :account)
54
+ # => [{"id"=>1, "account"=>"account1"}, {"id"=>2, "account"=>"account2"}]
55
+
56
+ User.where('id < 3').pluck_all(:id, 'account AS name')
57
+ # => [{"id"=>1, "name"=>"account1"}, {"id"=>2, "name"=>"account2"}]
58
+
59
+ User.where('id < 3').pluck_all('id, account AS name')
60
+ # => [{"id"=>1, "name"=>"account1"}, {"id"=>2, "name"=>"account2"}]
61
+ ```
62
+
63
+ ## Support Mongoid
64
+ ```rb
65
+ class User
66
+ include Mongoid::Document
67
+
68
+ field :name, type: String
69
+ field :age, type: Integer
70
+ end
71
+
72
+ User.pluck_all(:name, :age)
73
+ # => [
74
+ # {'name' => 'Pearl Shi' , 'age' => 18},
75
+ # {'name' => 'Rumble Huang', 'age' => 20},
76
+ # {'name' => 'Khiav Reoy' , 'age' => 20},
77
+ # ]
78
+ ```
79
+
80
+
81
+ ## Benchmark
82
+ ### Compare with `map` and `as_json`
83
+
84
+ `pluck_all` return raw `hash` data without loading a bunch of records, in that having better performace than using `map` and `as_json`. The following is the benchmark test on 191,093 users, where `users` table have 51 columns.
85
+
86
+ ```rb
87
+ user system total real
88
+ map 36.110000 61.200000 97.310000 ( 99.535375)
89
+ select + map 10.530000 0.660000 11.190000 ( 12.550974)
90
+ select + as_json 49.040000 1.120000 50.160000 ( 55.417534)
91
+ pluck_all 3.310000 0.100000 3.410000 ( 3.527775)
92
+ ```
93
+ Test by `benchmark-ips` and `limit 100` in each iteration:
94
+ ```
95
+ Warming up --------------------------------------
96
+ map 1.000 i/100ms
97
+ select + map 28.000 i/100ms
98
+ select + as_json 7.000 i/100ms
99
+ pluck_all 54.000 i/100ms
100
+ Calculating -------------------------------------
101
+ map 14.230 (± 0.0%) i/s - 72.000 in 5.065349s
102
+ select + map 281.638 (± 4.6%) i/s - 1.428k in 5.081216s
103
+ select + as_json 73.241 (± 4.1%) i/s - 371.000 in 5.076235s
104
+ pluck_all 539.057 (± 6.7%) i/s - 2.700k in 5.034858s
105
+
106
+ Comparison:
107
+ pluck_all: 539.1 i/s
108
+ select + map: 281.6 i/s - 1.91x slower
109
+ select + as_json: 73.2 i/s - 7.36x slower
110
+ map: 14.2 i/s - 37.88x slower
111
+ ```
112
+ [test script](https://github.com/khiav223577/pluck_all/issues/18)
113
+
114
+ ### Compare with [pluck_to_hash](https://github.com/girishso/pluck_to_hash) gem
115
+
116
+ `pluck_all` has better performace since it uses raw `hash` data from `ActiveRecord::Base.connection.select_all`, while `pluck_to_hash` uses `pluck` method, which calls `ActiveRecord::Base.connection.select_all` and transfers the raw `hash` data to `array` format, and then transfer the data to `hash` format again. The following benchmark shows the performance difference:
117
+
118
+ ```rb
119
+                                       user     system     total       real
120
+ pluck_to_hash 2.960000 0.130000 3.090000 ( 3.421640)
121
+ pluck_all 2.160000 0.120000 2.280000 ( 2.605118)
122
+ ```
123
+ Tested by `benchmark-ips` and `limit 1000` in each iteration:
124
+ ```
125
+ Warming up --------------------------------------
126
+ pluck_to_hash 7.000 i/100ms
127
+ pluck_all 9.000 i/100ms
128
+ Calculating -------------------------------------
129
+ pluck_to_hash 84.526 (± 4.7%) i/s - 427.000 in 5.065792s
130
+ pluck_all 95.133 (± 4.2%) i/s - 477.000 in 5.021555s
131
+
132
+ Comparison:
133
+ pluck_all: 95.1 i/s
134
+ pluck_to_hash: 84.5 i/s - 1.13x slower
135
+ ```
136
+ See the [test script](https://github.com/khiav223577/pluck_all/issues/18#issuecomment-325407080) for more details.
137
+
138
+ ## Other Support
139
+
140
+ ### Support globalize gem
141
+
142
+ ```rb
143
+ class Post < ActiveRecord::Base
144
+ translates :title
145
+ end
146
+ ```
147
+
148
+ ```rb
149
+ I18n.locale = :en
150
+ Post.pluck_all(:title)
151
+ # => [{ 'title' => 'english' }, { 'title' => 'english' }, ...]
152
+
153
+ I18n.locale = :'zh-TW'
154
+ Post.pluck_all(:title)
155
+ # => [{ 'title' => '中文' }, { 'title' => '中文' }, ...]
156
+ ```
157
+
158
+
159
+ ### Support Pluck Carrierwave Uploader (if you use carrierwave)
160
+ ```rb
161
+ User.where(xxx).pluck_all(:profile_pic).map{|s| s['profile_pic'] }
162
+ ```
163
+ is the same as
164
+ ```rb
165
+ User.where(xxx).map(&:profile_pic)
166
+ ```
167
+ If the uploader use something like: `model.id`, `model.name`
168
+ You may have to send these columns manually:
169
+ ```rb
170
+ User.where(xxx).cast_need_columns(%i[id name]).pluck_all(:id, :name, :profile_pic).map{|s| s['profile_pic'] }
171
+ ```
172
+
173
+ ## Development
174
+
175
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test_active_record` or `rake test_mongoid` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
176
+
177
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
178
+
179
+ ## Contributing
180
+
181
+ Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/pluck_all. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
182
+
183
+
184
+ ## License
185
+
186
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
187
+