pluck_to_hash 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/pluck_to_hash.rb +3 -7
- data/lib/pluck_to_hash/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 50f80958e9fbd475f3aa35590630c216cff7a1c2
         | 
| 4 | 
            +
              data.tar.gz: a27b0a038a4da7cab0412d1ed99dfceb5de20983
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
             | 
| 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 | 
             
            [](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( | 
| 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)  | 
| 59 | 
            +
            Brought to you by: [Cube Root Software](http://www.cuberoot.in) © 2015
         | 
    
        data/lib/pluck_to_hash.rb
    CHANGED
    
    | @@ -4,16 +4,12 @@ module PluckToHash | |
| 4 4 | 
             
              extend ActiveSupport::Concern
         | 
| 5 5 |  | 
| 6 6 | 
             
              module ClassMethods
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                   | 
| 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)
         | 
    
        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 | 
| 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- | 
| 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. | 
| 105 | 
            +
            rubygems_version: 2.4.5
         | 
| 106 106 | 
             
            signing_key: 
         | 
| 107 107 | 
             
            specification_version: 4
         | 
| 108 108 | 
             
            summary: Extend ActiveRecord pluck to return hash
         |