pluck_all 2.0.4 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,8 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.2
5
- - 2.3
5
+ - 2.6
6
+ - 2.7
6
7
  services:
7
8
  - mongodb
8
9
  env:
@@ -17,13 +18,20 @@ gemfile:
17
18
  - gemfiles/active_record_50.gemfile
18
19
  - gemfiles/active_record_51.gemfile
19
20
  - gemfiles/active_record_52.gemfile
21
+ - gemfiles/active_record_60.gemfile
20
22
  - gemfiles/mongoid_54.gemfile
21
23
  - gemfiles/mongoid_64.gemfile
22
24
  - gemfiles/mongoid_70.gemfile
23
25
  matrix:
24
26
  exclude:
27
+ - gemfile: gemfiles/active_record_32.gemfile
28
+ rvm: 2.6
29
+ - gemfile: gemfiles/active_record_32.gemfile
30
+ rvm: 2.7
25
31
  - gemfile: gemfiles/active_record_32.gemfile
26
32
  env: ORM_TYPE=MONGOID
33
+ - gemfile: gemfiles/active_record_42.gemfile
34
+ rvm: 2.7
27
35
  - gemfile: gemfiles/active_record_42.gemfile
28
36
  env: ORM_TYPE=MONGOID
29
37
  - gemfile: gemfiles/active_record_50.gemfile
@@ -32,6 +40,12 @@ matrix:
32
40
  env: ORM_TYPE=MONGOID
33
41
  - gemfile: gemfiles/active_record_52.gemfile
34
42
  env: ORM_TYPE=MONGOID
43
+ - gemfile: gemfiles/active_record_60.gemfile
44
+ rvm: 2.2
45
+ - gemfile: gemfiles/active_record_60.gemfile
46
+ env: ORM_TYPE=MONGOID
47
+ - gemfile: gemfiles/mongoid_54.gemfile
48
+ rvm: 2.7
35
49
  - gemfile: gemfiles/mongoid_54.gemfile
36
50
  env: ORM_TYPE=ACTIVE_RECORD
37
51
  - gemfile: gemfiles/mongoid_64.gemfile
@@ -39,8 +53,10 @@ matrix:
39
53
  - gemfile: gemfiles/mongoid_70.gemfile
40
54
  env: ORM_TYPE=ACTIVE_RECORD
41
55
  before_install:
42
- - gem i rubygems-update -v '<3' && update_rubygems
43
- - gem install bundler -v 1.17.3
56
+ - if `ruby -e 'exit(RUBY_VERSION.to_f < 2.7)'`; then
57
+ gem i rubygems-update -v '< 3' && update_rubygems;
58
+ gem install bundler -v '< 2';
59
+ fi
44
60
  - gem --version
45
61
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
46
62
  - chmod +x ./cc-test-reporter
@@ -1,60 +1,67 @@
1
- ## Change Log
2
-
3
- ### [upcoming](https://github.com/khiav223577/pluck_all/compare/v2.0.3...HEAD) 2018/12/21
4
- - [#35](https://github.com/khiav223577/pluck_all/pull/35) refactor #test_pluck_with_includes (@khiav223577)
5
- - [#34](https://github.com/khiav223577/pluck_all/pull/34) Provide Arel support as well (@snkashis)
6
- - [#33](https://github.com/khiav223577/pluck_all/pull/33) Fix gemfile path in bin/setup (@snkashis)
7
- - [#32](https://github.com/khiav223577/pluck_all/pull/32) Move patches into separate files (@khiav223577)
8
-
9
- ### [v2.0.3](https://github.com/khiav223577/pluck_all/compare/v2.0.2...v2.0.3) 2018/07/19
10
- - [#30](https://github.com/khiav223577/pluck_all/pull/30) Fix: includes + pluck_all results in strange output (@khiav223577)
11
-
12
- ### [v2.0.2](https://github.com/khiav223577/pluck_all/compare/v2.0.1...v2.0.2) 2018/06/29
13
- - [#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)
14
- - [#27](https://github.com/khiav223577/pluck_all/pull/27) [Feature] Mongoid Hooks And Tests Separation (@berniechiu)
15
- - [#26](https://github.com/khiav223577/pluck_all/pull/26) [FIX] Wrong Module Skipped (@berniechiu)
16
-
17
- ### [v2.0.1](https://github.com/khiav223577/pluck_all/compare/v2.0.0...v2.0.1) 2018/05/27
18
- - [#25](https://github.com/khiav223577/pluck_all/pull/25) Fix that project without mongoid will raise LoadError (@khiav223577)
19
-
20
- ### [v2.0.0](https://github.com/khiav223577/pluck_all/compare/v1.2.4...v2.0.0) 2018/05/27
21
- - [#24](https://github.com/khiav223577/pluck_all/pull/24) Support Mongoid! (@khiav223577)
22
- - [#23](https://github.com/khiav223577/pluck_all/pull/23) Refactoring Coding Style (@khiav223577)
23
- - [#22](https://github.com/khiav223577/pluck_all/pull/22) test Rails 5.2 (@khiav223577)
24
- - [#21](https://github.com/khiav223577/pluck_all/pull/21) should test both 5.0.x and 5.1.x (@khiav223577)
25
- - [#20](https://github.com/khiav223577/pluck_all/pull/20) test pluck_all in rails 5.1.x (@khiav223577)
26
- - [#19](https://github.com/khiav223577/pluck_all/pull/19) add test cases to test `join` with table name and `alias` (@khiav223577)
27
-
28
- ### [v1.2.4](https://github.com/khiav223577/pluck_all/compare/v1.2.3...v1.2.4) 2017/04/11
29
- - [#17](https://github.com/khiav223577/pluck_all/pull/17) supports carrierwave 1.0.0 (@khiav223577)
30
-
31
- ### [v1.2.3](https://github.com/khiav223577/pluck_all/compare/v1.2.2...v1.2.3) 2017/04/03
32
- - [#14](https://github.com/khiav223577/pluck_all/pull/14) use mass assign to assign values (@khiav223577)
33
- - [#16](https://github.com/khiav223577/pluck_all/pull/16) Checking if Class has CarrierWave loaded (@basex)
34
- - [#15](https://github.com/khiav223577/pluck_all/pull/15) Restrict dependency to activerecord (@basex)
35
-
36
- ### [v1.2.2](https://github.com/khiav223577/pluck_all/compare/v1.2.1...v1.2.2) 2017/03/14
37
- - [#13](https://github.com/khiav223577/pluck_all/pull/13) Model.none.pluck_all(..) should return empty array instead of raising exception (@khiav223577)
38
- - [#12](https://github.com/khiav223577/pluck_all/pull/12) test other ruby version (@khiav223577)
39
-
40
- ### [v1.2.1](https://github.com/khiav223577/pluck_all/compare/v1.2.0...v1.2.1) 2017/01/24
41
- - [#11](https://github.com/khiav223577/pluck_all/pull/11) always return carrierwave uploader if possible (@khiav223577)
42
- - [#10](https://github.com/khiav223577/pluck_all/pull/10) change pluck_all return value of carrierwave column (@khiav223577)
43
-
44
- ### [v1.2.0](https://github.com/khiav223577/pluck_all/compare/v1.1.2...v1.2.0) 2017/01/24
45
- - [#5](https://github.com/khiav223577/pluck_all/pull/5) Support casting CarrierWave url (@khiav223577)
46
- - [#9](https://github.com/khiav223577/pluck_all/pull/9) need ActiveRecord version not Rails version (@khiav223577)
47
- - [#8](https://github.com/khiav223577/pluck_all/pull/8) Upgrade rake version in development (@khiav223577)
48
-
49
- ### [v1.1.2](https://github.com/khiav223577/pluck_all/compare/v1.1.1...v1.1.2) 2017/01/06
50
- - [#7](https://github.com/khiav223577/pluck_all/pull/7) fix pluck_all with join (@khiav223577)
51
-
52
- ### [v1.1.1](https://github.com/khiav223577/pluck_all/compare/v1.1.0...v1.1.1) 2017/01/01
53
- - [#4](https://github.com/khiav223577/pluck_all/pull/4) add code climate (@khiav223577)
54
-
55
- ### [v1.1.0](https://github.com/khiav223577/pluck_all/compare/v1.0.1...v1.1.0) 2016/12/21
56
- - [#3](https://github.com/khiav223577/pluck_all/pull/3) Feature/pluck array (@khiav223577)
57
-
58
- ### [v1.0.1](https://github.com/khiav223577/pluck_all/compare/v1.0.0...v1.0.1) 2016/12/20
59
- - [#2](https://github.com/khiav223577/pluck_all/pull/2) test with multiple rails version (@khiav223577)
60
- - [#1](https://github.com/khiav223577/pluck_all/pull/1) add basic test cases (@khiav223577)
1
+ ## Change Log
2
+
3
+ ### [upcoming](https://github.com/khiav223577/pluck_all/compare/v2.0.4...HEAD) 2019/12/19
4
+ - [#43](https://github.com/khiav223577/pluck_all/pull/43) Use rails_compatibility to get attribute_types for better compatibility (@khiav223577)
5
+ - [#41](https://github.com/khiav223577/pluck_all/pull/41) Support Rails 6.0 (@khiav223577)
6
+
7
+ ### [v2.0.4](https://github.com/khiav223577/pluck_all/compare/v2.0.3...v2.0.4) 2019/04/04
8
+ - [#40](https://github.com/khiav223577/pluck_all/pull/40) Fix: inconsistent with pluck when having `select` on relation (@khiav223577)
9
+ - [#39](https://github.com/khiav223577/pluck_all/pull/39) Fix issue#38 (@MasashiYokota)
10
+ - [#36](https://github.com/khiav223577/pluck_all/pull/36) Fix: broken test cases after bundler 2.0 was released (@khiav223577)
11
+ - [#35](https://github.com/khiav223577/pluck_all/pull/35) refactor #test_pluck_with_includes (@khiav223577)
12
+ - [#34](https://github.com/khiav223577/pluck_all/pull/34) Provide Arel support as well (@snkashis)
13
+ - [#33](https://github.com/khiav223577/pluck_all/pull/33) Fix gemfile path in bin/setup (@snkashis)
14
+ - [#32](https://github.com/khiav223577/pluck_all/pull/32) Move patches into separate files (@khiav223577)
15
+
16
+ ### [v2.0.3](https://github.com/khiav223577/pluck_all/compare/v2.0.2...v2.0.3) 2018/07/19
17
+ - [#30](https://github.com/khiav223577/pluck_all/pull/30) Fix: includes + pluck_all results in strange output (@khiav223577)
18
+
19
+ ### [v2.0.2](https://github.com/khiav223577/pluck_all/compare/v2.0.1...v2.0.2) 2018/06/29
20
+ - [#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)
21
+ - [#27](https://github.com/khiav223577/pluck_all/pull/27) [Feature] Mongoid Hooks And Tests Separation (@berniechiu)
22
+ - [#26](https://github.com/khiav223577/pluck_all/pull/26) [FIX] Wrong Module Skipped (@berniechiu)
23
+
24
+ ### [v2.0.1](https://github.com/khiav223577/pluck_all/compare/v2.0.0...v2.0.1) 2018/05/27
25
+ - [#25](https://github.com/khiav223577/pluck_all/pull/25) Fix that project without mongoid will raise LoadError (@khiav223577)
26
+
27
+ ### [v2.0.0](https://github.com/khiav223577/pluck_all/compare/v1.2.4...v2.0.0) 2018/05/27
28
+ - [#24](https://github.com/khiav223577/pluck_all/pull/24) Support Mongoid! (@khiav223577)
29
+ - [#23](https://github.com/khiav223577/pluck_all/pull/23) Refactoring Coding Style (@khiav223577)
30
+ - [#22](https://github.com/khiav223577/pluck_all/pull/22) test Rails 5.2 (@khiav223577)
31
+ - [#21](https://github.com/khiav223577/pluck_all/pull/21) should test both 5.0.x and 5.1.x (@khiav223577)
32
+ - [#20](https://github.com/khiav223577/pluck_all/pull/20) test pluck_all in rails 5.1.x (@khiav223577)
33
+ - [#19](https://github.com/khiav223577/pluck_all/pull/19) add test cases to test `join` with table name and `alias` (@khiav223577)
34
+
35
+ ### [v1.2.4](https://github.com/khiav223577/pluck_all/compare/v1.2.3...v1.2.4) 2017/04/11
36
+ - [#17](https://github.com/khiav223577/pluck_all/pull/17) supports carrierwave 1.0.0 (@khiav223577)
37
+
38
+ ### [v1.2.3](https://github.com/khiav223577/pluck_all/compare/v1.2.2...v1.2.3) 2017/04/03
39
+ - [#14](https://github.com/khiav223577/pluck_all/pull/14) use mass assign to assign values (@khiav223577)
40
+ - [#16](https://github.com/khiav223577/pluck_all/pull/16) Checking if Class has CarrierWave loaded (@basex)
41
+ - [#15](https://github.com/khiav223577/pluck_all/pull/15) Restrict dependency to activerecord (@basex)
42
+
43
+ ### [v1.2.2](https://github.com/khiav223577/pluck_all/compare/v1.2.1...v1.2.2) 2017/03/14
44
+ - [#13](https://github.com/khiav223577/pluck_all/pull/13) Model.none.pluck_all(..) should return empty array instead of raising exception (@khiav223577)
45
+ - [#12](https://github.com/khiav223577/pluck_all/pull/12) test other ruby version (@khiav223577)
46
+
47
+ ### [v1.2.1](https://github.com/khiav223577/pluck_all/compare/v1.2.0...v1.2.1) 2017/01/24
48
+ - [#11](https://github.com/khiav223577/pluck_all/pull/11) always return carrierwave uploader if possible (@khiav223577)
49
+ - [#10](https://github.com/khiav223577/pluck_all/pull/10) change pluck_all return value of carrierwave column (@khiav223577)
50
+
51
+ ### [v1.2.0](https://github.com/khiav223577/pluck_all/compare/v1.1.2...v1.2.0) 2017/01/24
52
+ - [#5](https://github.com/khiav223577/pluck_all/pull/5) Support casting CarrierWave url (@khiav223577)
53
+ - [#9](https://github.com/khiav223577/pluck_all/pull/9) need ActiveRecord version not Rails version (@khiav223577)
54
+ - [#8](https://github.com/khiav223577/pluck_all/pull/8) Upgrade rake version in development (@khiav223577)
55
+
56
+ ### [v1.1.2](https://github.com/khiav223577/pluck_all/compare/v1.1.1...v1.1.2) 2017/01/06
57
+ - [#7](https://github.com/khiav223577/pluck_all/pull/7) fix pluck_all with join (@khiav223577)
58
+
59
+ ### [v1.1.1](https://github.com/khiav223577/pluck_all/compare/v1.1.0...v1.1.1) 2017/01/01
60
+ - [#4](https://github.com/khiav223577/pluck_all/pull/4) add code climate (@khiav223577)
61
+
62
+ ### [v1.1.0](https://github.com/khiav223577/pluck_all/compare/v1.0.1...v1.1.0) 2016/12/21
63
+ - [#3](https://github.com/khiav223577/pluck_all/pull/3) Feature/pluck array (@khiav223577)
64
+
65
+ ### [v1.0.1](https://github.com/khiav223577/pluck_all/compare/v1.0.0...v1.0.1) 2016/12/20
66
+ - [#2](https://github.com/khiav223577/pluck_all/pull/2) test with multiple rails version (@khiav223577)
67
+ - [#1](https://github.com/khiav223577/pluck_all/pull/1) add basic test cases (@khiav223577)
@@ -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/
@@ -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,130 +1,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://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, 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](http://meltingice.net/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 in the future will break this.
16
-
17
-
18
-
19
- ## Installation
20
-
21
- Add this line to your application's Gemfile:
22
-
23
- ```ruby
24
- gem 'pluck_all'
25
- ```
26
-
27
- And then execute:
28
-
29
- $ bundle
30
-
31
- Or install it yourself as:
32
-
33
- $ gem install pluck_all
34
-
35
- ## Usage
36
-
37
- ### pluck to array
38
-
39
- Behaves the same as the Rails 4 pluck, but you can use it in Rails 3
40
-
41
- ```rb
42
- User.where('id < 3').pluck_array(:id, :account)
43
- # => [[1, 'account1'], [2, 'account2']]
44
- ```
45
-
46
- ### pluck to hash
47
-
48
- Similar to `pluck_array`, but return hash instead.
49
-
50
- ```rb
51
- User.where('id < 3').pluck_all(:id, :account)
52
- # => [{"id"=>1, "account"=>"account1"}, {"id"=>2, "account"=>"account2"}]
53
-
54
- User.where('id < 3').pluck_all('id, account AS name')
55
- # => [{"id"=>1, "name"=>"account1"}, {"id"=>2, "name"=>"account2"}]
56
- ```
57
-
58
- ## Support Mongoid
59
- ```rb
60
- class User
61
- include Mongoid::Document
62
-
63
- field :name, type: String
64
- field :age, type: Integer
65
- end
66
-
67
- User.pluck_all(:name, :age)
68
- # => [
69
- # {'name' => 'Pearl Shi' , 'age' => 18},
70
- # {'name' => 'Rumble Huang', 'age' => 20},
71
- # {'name' => 'Khiav Reoy' , 'age' => 20},
72
- # ]
73
- ```
74
-
75
-
76
- ## Benchmark
77
- ### Compare with `map` and `as_json`
78
-
79
- `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.
80
-
81
- ```rb
82
- user system total real
83
- map 36.110000 61.200000 97.310000 ( 99.535375)
84
- select + map 10.530000 0.660000 11.190000 ( 12.550974)
85
- select + as_json 49.040000 1.120000 50.160000 ( 55.417534)
86
- pluck_all 3.310000 0.100000 3.410000 ( 3.527775)
87
- ```
88
- [test script](https://github.com/khiav223577/pluck_all/issues/18)
89
-
90
- ### Compare with [pluck_to_hash](https://github.com/girishso/pluck_to_hash) gem
91
-
92
- `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 test uses same datebase as above.
93
-
94
- ```rb
95
-                                       user     system     total       real
96
- pluck_to_hash 2.960000 0.130000 3.090000 ( 3.421640)
97
- pluck_all 2.160000 0.120000 2.280000 ( 2.605118)
98
- ```
99
- [test script](https://github.com/khiav223577/pluck_all/issues/18#issuecomment-325407080)
100
-
101
- ## Other Support
102
- ### Support Pluck Carrierwave Uploader (if you use carrierwave)
103
- ```rb
104
- User.where(xxx).pluck_all(:profile_pic).map{|s| s['profile_pic'] }
105
- ```
106
- is the same as
107
- ```rb
108
- User.where(xxx).map(&:profile_pic)
109
- ```
110
- If the uploader use something like: `model.id`, `model.name`
111
- You may have to send these columns manually:
112
- ```rb
113
- User.where(xxx).cast_need_columns(%i(id, name)).pluck_all(:id, :name, :profile_pic).map{|s| s['profile_pic'] }
114
- ```
115
-
116
- ## Development
117
-
118
- 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.
119
-
120
- 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).
121
-
122
- ## Contributing
123
-
124
- 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.
125
-
126
-
127
- ## License
128
-
129
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
130
-
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
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
+