pluck_each 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e38a2e5de6b397dab4950becd1de9a80b703dd4e
4
- data.tar.gz: 0f3798ecff31d3f35ece1f6ecedcea9ce657a233
3
+ metadata.gz: a808f819a95611a329a5a724924b41ff62e6bbb7
4
+ data.tar.gz: d2c9cc635521e5ffd1fbc5e8f09c9dcf23d3a2c1
5
5
  SHA512:
6
- metadata.gz: 4cfd3aff95b389605210a1721da6361de08ef10ed15f70e269be0f846f48811afa7f4791fa559bdc13def4da414a0545e61a64fb2b1b118c144971740d9f753f
7
- data.tar.gz: d3009c05a01c391bda8294158abab7fe8d45ad432fefa64304cd99a50f4c0f11d675d68d9c9ad3b050709a4e955eb7fca651bb8f1f6948ff9220d87d0a11178b
6
+ metadata.gz: 0c72e5d7bef5021a2d9563fea25c94f9abbdd78f7c6ec2b497134a3d66816df7e902fe8b7efe9ae4817819ad379bbcf44cc4b16d0ba9c54bdac7e2031967b38f
7
+ data.tar.gz: d332a5c55fa5a6d969172d908e13f50e1f5c810d95cd64a146ebdf326201aeb406b180e5627cfa624fa722598e6393638271434befe8dee501521b71373ee451
@@ -1,3 +1,3 @@
1
1
  module PluckEach
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/pluck_each.rb CHANGED
@@ -20,6 +20,7 @@ module ActiveRecord
20
20
 
21
21
  # Ensure the primary key is selected so we can use it as an offset
22
22
  id_in_columns_requested = string_column_names.include?(primary_key)
23
+ id_only_field_requested = id_in_columns_requested && string_column_names.size == 1
23
24
  string_column_names.unshift(primary_key) unless id_in_columns_requested
24
25
  id_position_in_response = string_column_names.index(primary_key)
25
26
 
@@ -33,12 +34,16 @@ module ActiveRecord
33
34
  batch = batch_relation.pluck(*string_column_names)
34
35
  break if batch.empty?
35
36
 
36
- primary_key_offset = batch.last.at(id_position_in_response)
37
+ primary_key_offset = batch.last
37
38
 
38
- unless id_in_columns_requested
39
- batch.collect! do |record|
40
- record.delete_at(id_position_in_response)
41
- record
39
+ if !id_only_field_requested
40
+ primary_key_offset = primary_key_offset.at(id_position_in_response)
41
+
42
+ unless id_in_columns_requested
43
+ batch.collect! do |record|
44
+ record.delete_at(id_position_in_response)
45
+ record
46
+ end
42
47
  end
43
48
  end
44
49
 
@@ -30,6 +30,16 @@ describe PluckEach do
30
30
  User.create(:first_name => '5', :last_name => '5')
31
31
  end
32
32
 
33
+ it 'plucks :id when only field requested' do
34
+ values = []
35
+ User.all.pluck_each(:id) do |id|
36
+ values << id
37
+ end
38
+
39
+ values.sort!
40
+ values.must_equal User.all.pluck(:id).sort
41
+ end
42
+
33
43
  it 'plucks only the fields requested' do
34
44
  values = []
35
45
  User.all.pluck_each(:first_name) do |first_name|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluck_each
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt