pluck_to_hash 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45a005c62922864984b081283ef1f8f17ef44b8e
4
- data.tar.gz: baa2f5a2469c260fa8cb2557bf3e5c517e0bed58
3
+ metadata.gz: 50f80958e9fbd475f3aa35590630c216cff7a1c2
4
+ data.tar.gz: a27b0a038a4da7cab0412d1ed99dfceb5de20983
5
5
  SHA512:
6
- metadata.gz: 3affbda10f60984f4ae0f01a88f394207f198e5401a6bb76f10066f8857f6a267dce94808c5b99ebdbd217eb8f403560c9a195b11102e7beca95258d50b60b57
7
- data.tar.gz: e2f318965a9e1579d4943a8550cb69a347bcfb3fe4e440aaf8d8919f2d5f0fe261041bae6622c0116b523ecbf0a70093b4aab1fd66087bc071a2a022ee45aa32
6
+ metadata.gz: a6c853840f4f755e08d180f64d4acc3949f4f4e804242ff711ca33165929d80e37f483252a7c0c8c8040d824d81f744f8c709a5940f3f5c1e0691bc5ffab0344
7
+ data.tar.gz: c8ce4c1cd4cf4c3d97ff9217cba31ddc70caf7be6b89c0ca92e30160ea50a0901a93cc1ad58443d16c9d8885963990b05b770fca92f50640a16c49d68cec7627
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # What is that for?
2
2
 
3
- Extend ActiveRecord pluck to return hash instead of an array. Useful when plucking multiple columns for rendering json for example.
3
+ Extends ActiveRecord by adding `pluck_to_hash` method that returns array of hashes instead of array of arrays. Useful when plucking multiple columns for rendering json or you need to access individual fields in your view for example.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/pluck_to_hash.png)](http://badge.fury.io/rb/pluck_to_hash)
6
6
 
7
-
8
7
  ## Installation
9
8
 
10
9
  Add this line to your application's Gemfile:
@@ -26,7 +25,7 @@ Or install it yourself as:
26
25
  Usage is similar to `ActiveRecord.pluck`, for example
27
26
 
28
27
  ```ruby
29
- Post.limit(2).pluck_to_hash([:id, :title])
28
+ Post.limit(2).pluck_to_hash(:id, :title)
30
29
  #
31
30
  # [{:id=>213, :title=>"foo"}, {:id=>214, :title=>"bar"}]
32
31
  #
@@ -57,4 +56,4 @@ Post.limit(2).pluck_h(:id)
57
56
  ## Licence
58
57
  MIT License
59
58
 
60
- Brought to you by: [Cube Root Software](http://www.cuberoot.in) (c) 2015
59
+ Brought to you by: [Cube Root Software](http://www.cuberoot.in) © 2015
@@ -4,16 +4,12 @@ module PluckToHash
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  module ClassMethods
7
- def pluck_to_hash(keys)
8
- if keys.is_a? Array
9
- pluck(*keys).map{|row| Hash[*[keys, row].transpose.flatten]}
10
- else
11
- pluck(*keys).map{|row| Hash[*[[keys], [row]].transpose.flatten]}
12
- end
7
+ def pluck_to_hash(*keys)
8
+ pluck(*keys).map{|row| Hash[Array(keys).zip(Array(row))]}
13
9
  end
14
10
 
15
11
  alias_method :pluck_h, :pluck_to_hash
16
12
  end
17
13
  end
18
14
 
19
- ActiveRecord::Base.send(:include, PluckToHash)
15
+ ActiveRecord::Base.send(:include, PluckToHash)
@@ -1,3 +1,3 @@
1
1
  module PluckToHash
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluck_to_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Girish S
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.2.2
105
+ rubygems_version: 2.4.5
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Extend ActiveRecord pluck to return hash