pluck_to_hash 1.0.1 → 1.0.2
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/lib/pluck_to_hash.rb +2 -3
 - data/lib/pluck_to_hash/version.rb +1 -1
 - data/spec/migrations.rb +2 -0
 - data/spec/pluck_to_hash_spec.rb +7 -0
 - data/spec/support/shared_examples.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4395818804a29d19184c864ffb2821b3f12af899
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 10e67c6767899d3e999ef94f9ab2ad252fe81b6a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 4463d4dfa93540cbfc9fcf28fc8048188111cee7b51c846e9324ac1d2c09cb1888b7f4e6635e17eb449475a62c82b769009f932fdf8269e4a346cd2deafc2ebc
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 664581475e18bc8d3739f65111818fb09d534fc14cfc336dec703a1572a52df2b7443b1857e08e57c04872973a66cef15624afd5bac2248345489c7f9f797d46
         
     | 
    
        data/lib/pluck_to_hash.rb
    CHANGED
    
    | 
         @@ -39,10 +39,9 @@ module PluckToHash 
     | 
|
| 
       39 
39 
     | 
    
         
             
                    if keys.blank?
         
     | 
| 
       40 
40 
     | 
    
         
             
                      [column_names, column_names]
         
     | 
| 
       41 
41 
     | 
    
         
             
                    else
         
     | 
| 
       42 
     | 
    
         
            -
                      ks = keys.map{|k| k.instance_of?(String) ? k.split(",") : k}.flatten
         
     | 
| 
       43 
42 
     | 
    
         
             
                      [
         
     | 
| 
       44 
     | 
    
         
            -
                         
     | 
| 
       45 
     | 
    
         
            -
                         
     | 
| 
      
 43 
     | 
    
         
            +
                        keys,
         
     | 
| 
      
 44 
     | 
    
         
            +
                        keys.map do |k|
         
     | 
| 
       46 
45 
     | 
    
         
             
                          case k
         
     | 
| 
       47 
46 
     | 
    
         
             
                          when String
         
     | 
| 
       48 
47 
     | 
    
         
             
                            k.split(/\bas\b/i)[-1].strip.to_sym
         
     | 
    
        data/spec/migrations.rb
    CHANGED
    
    
    
        data/spec/pluck_to_hash_spec.rb
    CHANGED
    
    | 
         @@ -34,6 +34,13 @@ describe 'PluckToHash' do 
     | 
|
| 
       34 
34 
     | 
    
         
             
                      { test_attribute: nil, serialized_attribute: ['Comonad'] }.with_indifferent_access
         
     | 
| 
       35 
35 
     | 
    
         
             
                    ]
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  it 'plucks coalesce as correctly' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                    TestModel.pluck_to_hash('coalesce(sum(price_1 - price_2), 0) as difference', 'count(test_models.id) as count').each do |result|
         
     | 
| 
      
 40 
     | 
    
         
            +
                      expect(result).to have_key('difference')
         
     | 
| 
      
 41 
     | 
    
         
            +
                      expect(result).to have_key('count')
         
     | 
| 
      
 42 
     | 
    
         
            +
                    end
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
       37 
44 
     | 
    
         
             
                end
         
     | 
| 
       38 
45 
     | 
    
         
             
              end
         
     | 
| 
       39 
46 
     | 
    
         
             
            end
         
     | 
| 
         @@ -41,7 +41,7 @@ shared_context 'essentials' do 
     | 
|
| 
       41 
41 
     | 
    
         
             
              end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
              it 'works with join' do
         
     | 
| 
       44 
     | 
    
         
            -
                TestModel.joins(:test_model_children).pluck_to_hash('test_models.id, test_model_children.id').each do |hash|
         
     | 
| 
      
 44 
     | 
    
         
            +
                TestModel.joins(:test_model_children).pluck_to_hash('test_models.id', 'test_model_children.id').each do |hash|
         
     | 
| 
       45 
45 
     | 
    
         
             
                  expect(hash).to have_key('test_models.id')
         
     | 
| 
       46 
46 
     | 
    
         
             
                  expect(hash).to have_key('test_model_children.id')
         
     | 
| 
       47 
47 
     | 
    
         
             
                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: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Girish S
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-08-09 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |