pluck_each 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/pluck_each/version.rb +1 -1
- data/lib/pluck_each.rb +8 -1
- data/pluck_each.gemspec +2 -2
- data/spec/pluck_each_spec.rb +8 -8
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1251afdb2cfb174e19fb429dc792037908275e3de39125de5704a8783b19d3c5
|
4
|
+
data.tar.gz: fa3759bccd4eac1e27508cc95f5f18c0a0c8106bad171ac7fe2e99ecce280864
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ef9e0c7e2fd32ffbd2eadf5f0dd678a7f81777f683f0d18223680dbc9ca8f51272e219df1730cceadaff7e214c5b36b20b6ce8fda764f885707780969c3f814
|
7
|
+
data.tar.gz: 0ba161fd79eba6c7542affaa794e26013055cd781cd13990806725280e665e88f5920f61cc18134638e0a8a6bced183a4a080114829a7af724006339fe8ea851
|
data/lib/pluck_each/version.rb
CHANGED
data/lib/pluck_each.rb
CHANGED
@@ -8,6 +8,8 @@ end
|
|
8
8
|
module ActiveRecord
|
9
9
|
module Batches
|
10
10
|
|
11
|
+
IS_RAILS_6_1_PLUS = ::Gem::Version.new(::ActiveRecord.version) >= ::Gem::Version.new("6.1.0")
|
12
|
+
|
11
13
|
def pluck_each(*args)
|
12
14
|
pluck_in_batches(*args) do |values|
|
13
15
|
values.each { |value| yield value }
|
@@ -27,7 +29,12 @@ module ActiveRecord
|
|
27
29
|
relation = self
|
28
30
|
batch_size = options[:batch_size] || 1000
|
29
31
|
|
30
|
-
|
32
|
+
if IS_RAILS_6_1_PLUS
|
33
|
+
relation = relation.reorder(batch_order(:asc)).limit(batch_size)
|
34
|
+
else
|
35
|
+
relation = relation.reorder(batch_order).limit(batch_size)
|
36
|
+
end
|
37
|
+
|
31
38
|
batch_relation = relation
|
32
39
|
|
33
40
|
loop do
|
data/pluck_each.gemspec
CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "activerecord", "> 3.2.0"
|
22
22
|
spec.add_dependency "activesupport", "> 3.0.0"
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
25
|
spec.add_development_dependency "minitest"
|
26
26
|
spec.add_development_dependency "mocha"
|
27
27
|
spec.add_development_dependency "pry"
|
28
|
-
spec.add_development_dependency "rake", "
|
28
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
29
29
|
end
|
data/spec/pluck_each_spec.rb
CHANGED
@@ -12,11 +12,11 @@ describe PluckEach do
|
|
12
12
|
|
13
13
|
describe 'API' do
|
14
14
|
it 'adds pluck_each to Arel relation nodes' do
|
15
|
-
User.all.must_respond_to :pluck_each
|
15
|
+
_(User.all).must_respond_to :pluck_each
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'adds pluck_in_batches to Arel relation nodes' do
|
19
|
-
User.all.must_respond_to :pluck_in_batches
|
19
|
+
_(User.all).must_respond_to :pluck_in_batches
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -43,7 +43,7 @@ describe PluckEach do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
values.sort!
|
46
|
-
values.must_equal ["1", "2", "3"]
|
46
|
+
_(values).must_equal ["1", "2", "3"]
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'plucks :id when only field requested' do
|
@@ -53,7 +53,7 @@ describe PluckEach do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
values.sort!
|
56
|
-
values.must_equal User.all.pluck(:id).sort
|
56
|
+
_(values).must_equal User.all.pluck(:id).sort
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'plucks only the fields requested' do
|
@@ -63,7 +63,7 @@ describe PluckEach do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
values.sort!
|
66
|
-
values.must_equal ['1', '2', '3', '4', '5']
|
66
|
+
_(values).must_equal ['1', '2', '3', '4', '5']
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'allows batch_size in options to determine batch size' do
|
@@ -74,9 +74,9 @@ describe PluckEach do
|
|
74
74
|
count += 1
|
75
75
|
end
|
76
76
|
|
77
|
-
count.must_equal(5)
|
77
|
+
_(count).must_equal(5)
|
78
78
|
values.sort!
|
79
|
-
values.must_equal ['1', '2', '3', '4', '5']
|
79
|
+
_(values).must_equal ['1', '2', '3', '4', '5']
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -97,7 +97,7 @@ describe PluckEach do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
batch_sizes.sort!
|
100
|
-
batch_sizes.must_equal [1, 2, 2]
|
100
|
+
_(batch_sizes).must_equal [1, 2, 2]
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluck_each
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 12.3.3
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 12.3.3
|
111
111
|
description: " pluck_each and plucK_in_batches ... should behave like find_each and
|
112
112
|
find_in_batches "
|
113
113
|
email:
|
@@ -130,7 +130,7 @@ homepage: ''
|
|
130
130
|
licenses:
|
131
131
|
- MIT
|
132
132
|
metadata: {}
|
133
|
-
post_install_message:
|
133
|
+
post_install_message:
|
134
134
|
rdoc_options: []
|
135
135
|
require_paths:
|
136
136
|
- lib
|
@@ -145,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
|
-
|
149
|
-
|
150
|
-
signing_key:
|
148
|
+
rubygems_version: 3.1.2
|
149
|
+
signing_key:
|
151
150
|
specification_version: 4
|
152
151
|
summary: pluck_each and plucK_in_batches ... should behave like find_each and find_in_batches
|
153
152
|
test_files:
|