pluck_all 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,4 @@
1
1
  sudo: false
2
- env:
3
- global:
4
- - CC_TEST_REPORTER_ID=db72eba1ff8fb1329dae5fb9b9dcd234243899d7a464ceb374e14a05ead27b7c
5
2
  language: ruby
6
3
  rvm:
7
4
  - 2.2
@@ -9,8 +6,11 @@ rvm:
9
6
  services:
10
7
  - mongodb
11
8
  env:
12
- - ORM_TYPE=ACTIVE_RECORD
13
- - ORM_TYPE=MONGOID
9
+ global:
10
+ - CC_TEST_REPORTER_ID=db72eba1ff8fb1329dae5fb9b9dcd234243899d7a464ceb374e14a05ead27b7c
11
+ matrix:
12
+ - ORM_TYPE=ACTIVE_RECORD
13
+ - ORM_TYPE=MONGOID
14
14
  gemfile:
15
15
  - gemfiles/active_record_32.gemfile
16
16
  - gemfiles/active_record_42.gemfile
@@ -39,8 +39,8 @@ matrix:
39
39
  - gemfile: gemfiles/mongoid_70.gemfile
40
40
  env: ORM_TYPE=ACTIVE_RECORD
41
41
  before_install:
42
- - gem install bundler
43
- - gem update --system
42
+ - gem i rubygems-update -v '<3' && update_rubygems
43
+ - gem install bundler -v 1.17.3
44
44
  - gem --version
45
45
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
46
46
  - chmod +x ./cc-test-reporter
@@ -1,51 +1,60 @@
1
- ## Change Log
2
-
3
- ### [upcoming](https://github.com/khiav223577/pluck_all/compare/v2.0.1...HEAD) 2018/06/29
4
- - [#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)
5
- - [#27](https://github.com/khiav223577/pluck_all/pull/27) [Feature] Mongoid Hooks And Tests Separation (@berniechiu)
6
- - [#26](https://github.com/khiav223577/pluck_all/pull/26) [FIX] Wrong Module Skipped (@berniechiu)
7
-
8
- ### [v2.0.1](https://github.com/khiav223577/pluck_all/compare/v2.0.0...v2.0.1) 2018/05/27
9
- - [#25](https://github.com/khiav223577/pluck_all/pull/25) Fix that project without mongoid will raise LoadError (@khiav223577)
10
-
11
- ### [v2.0.0](https://github.com/khiav223577/pluck_all/compare/v1.2.4...v2.0.0) 2018/05/27
12
- - [#24](https://github.com/khiav223577/pluck_all/pull/24) Support Mongoid! (@khiav223577)
13
- - [#23](https://github.com/khiav223577/pluck_all/pull/23) Refactoring Coding Style (@khiav223577)
14
- - [#22](https://github.com/khiav223577/pluck_all/pull/22) test Rails 5.2 (@khiav223577)
15
- - [#21](https://github.com/khiav223577/pluck_all/pull/21) should test both 5.0.x and 5.1.x (@khiav223577)
16
- - [#20](https://github.com/khiav223577/pluck_all/pull/20) test pluck_all in rails 5.1.x (@khiav223577)
17
- - [#19](https://github.com/khiav223577/pluck_all/pull/19) add test cases to test `join` with table name and `alias` (@khiav223577)
18
-
19
- ### [v1.2.4](https://github.com/khiav223577/pluck_all/compare/v1.2.3...v1.2.4) 2017/04/11
20
- - [#17](https://github.com/khiav223577/pluck_all/pull/17) supports carrierwave 1.0.0 (@khiav223577)
21
-
22
- ### [v1.2.3](https://github.com/khiav223577/pluck_all/compare/v1.2.2...v1.2.3) 2017/04/03
23
- - [#14](https://github.com/khiav223577/pluck_all/pull/14) use mass assign to assign values (@khiav223577)
24
- - [#16](https://github.com/khiav223577/pluck_all/pull/16) Checking if Class has CarrierWave loaded (@basex)
25
- - [#15](https://github.com/khiav223577/pluck_all/pull/15) Restrict dependency to activerecord (@basex)
26
-
27
- ### [v1.2.2](https://github.com/khiav223577/pluck_all/compare/v1.2.1...v1.2.2) 2017/03/14
28
- - [#13](https://github.com/khiav223577/pluck_all/pull/13) Model.none.pluck_all(..) should return empty array instead of raising exception (@khiav223577)
29
- - [#12](https://github.com/khiav223577/pluck_all/pull/12) test other ruby version (@khiav223577)
30
-
31
- ### [v1.2.1](https://github.com/khiav223577/pluck_all/compare/v1.2.0...v1.2.1) 2017/01/24
32
- - [#11](https://github.com/khiav223577/pluck_all/pull/11) always return carrierwave uploader if possible (@khiav223577)
33
- - [#10](https://github.com/khiav223577/pluck_all/pull/10) change pluck_all return value of carrierwave column (@khiav223577)
34
-
35
- ### [v1.2.0](https://github.com/khiav223577/pluck_all/compare/v1.1.2...v1.2.0) 2017/01/24
36
- - [#5](https://github.com/khiav223577/pluck_all/pull/5) Support casting CarrierWave url (@khiav223577)
37
- - [#9](https://github.com/khiav223577/pluck_all/pull/9) need ActiveRecord version not Rails version (@khiav223577)
38
- - [#8](https://github.com/khiav223577/pluck_all/pull/8) Upgrade rake version in development (@khiav223577)
39
-
40
- ### [v1.1.2](https://github.com/khiav223577/pluck_all/compare/v1.1.1...v1.1.2) 2017/01/06
41
- - [#7](https://github.com/khiav223577/pluck_all/pull/7) fix pluck_all with join (@khiav223577)
42
-
43
- ### [v1.1.1](https://github.com/khiav223577/pluck_all/compare/v1.1.0...v1.1.1) 2017/01/01
44
- - [#4](https://github.com/khiav223577/pluck_all/pull/4) add code climate (@khiav223577)
45
-
46
- ### [v1.1.0](https://github.com/khiav223577/pluck_all/compare/v1.0.1...v1.1.0) 2016/12/21
47
- - [#3](https://github.com/khiav223577/pluck_all/pull/3) Feature/pluck array (@khiav223577)
48
-
49
- ### v1.0.1 2016/12/20
50
- - [#2](https://github.com/khiav223577/pluck_all/pull/2) test with multiple rails version (@khiav223577)
51
- - [#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.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,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,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, 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, 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
+