pluck_to_hash 1.0.1 → 1.0.2

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: df4cd9672a0e574e5521ce4715ff26824ce4cd10
4
- data.tar.gz: 4f3f7812b3e1fbb7765c66d50788035643aca3ca
3
+ metadata.gz: 4395818804a29d19184c864ffb2821b3f12af899
4
+ data.tar.gz: 10e67c6767899d3e999ef94f9ab2ad252fe81b6a
5
5
  SHA512:
6
- metadata.gz: 1b4d6fdafb153d7d83c5897de79a55994bd0e7bbd65ab94ce45699c28706374a9957917bbfdd6ebad8310e2f7440c434ef803cc6469ed6c044ca535de4dbb78e
7
- data.tar.gz: c6605c8f62008cbd7364d57f7c4d34c77d23049b0176f0962cee967e782159f9f08ec6fc6754e6329dd35efaa9877ebda3f73da7a0e671cf89e0150446cf730d
6
+ metadata.gz: 4463d4dfa93540cbfc9fcf28fc8048188111cee7b51c846e9324ac1d2c09cb1888b7f4e6635e17eb449475a62c82b769009f932fdf8269e4a346cd2deafc2ebc
7
+ data.tar.gz: 664581475e18bc8d3739f65111818fb09d534fc14cfc336dec703a1572a52df2b7443b1857e08e57c04872973a66cef15624afd5bac2248345489c7f9f797d46
@@ -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
- ks,
45
- ks.map do |k|
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
@@ -1,3 +1,3 @@
1
1
  module PluckToHash
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -7,6 +7,8 @@ def run_migrations
7
7
  create_table :test_models do |t|
8
8
  t.string :test_attribute
9
9
  t.string :serialized_attribute
10
+ t.integer :price_1
11
+ t.integer :price_2
10
12
  end
11
13
  create_table :test_model_children do |t|
12
14
  t.integer :test_model_id
@@ -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.1
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-06-30 00:00:00.000000000 Z
11
+ date: 2017-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler