lhs 5.6.5 → 5.6.6
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/lhs/concerns/record/batch.rb +3 -3
- data/lib/lhs/version.rb +1 -1
- data/spec/record/find_in_batches_spec.rb +32 -5
- 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: 69913ab2a3b45766bc83f1c9bbe146dc8222ad3b
|
4
|
+
data.tar.gz: 12aca78a7334087c9c93fc42b338eb58de74c57b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 829eb8c9a105d0aef36ebcb63878c038db3bbe8aa2fb7444aacdd0b534ddb0496c5e3f2464ea86977be03b1b6ad8c312c62b51cf54826b49fd8795b372f1ec2d
|
7
|
+
data.tar.gz: 0bb344b8a4ad023a8aa2deb125cde83bf381f340b3bcbd1bff68855fba7d86b151061a9fcf2887d9725369fa2515111a1715a3c77c2db9af389a3282321278f9
|
@@ -23,9 +23,9 @@ class LHS::Record
|
|
23
23
|
batch_size = options[:batch_size] || LHS::Pagination::DEFAULT_LIMIT
|
24
24
|
params = options[:params] || {}
|
25
25
|
loop do # as suggested by Matz
|
26
|
-
data = request(params: params.merge(
|
27
|
-
batch_size = data._raw[
|
28
|
-
left = data._raw[
|
26
|
+
data = request(params: params.merge(limit_key => batch_size, pagination_key => start))
|
27
|
+
batch_size = data._raw[limit_key]
|
28
|
+
left = data._raw[total_key].to_i - data._raw[pagination_key].to_i - data._raw[limit_key].to_i
|
29
29
|
yield new(data)
|
30
30
|
break if left <= 0
|
31
31
|
start += batch_size
|
data/lib/lhs/version.rb
CHANGED
@@ -5,13 +5,13 @@ describe LHS::Collection do
|
|
5
5
|
|
6
6
|
let(:limit) { 100 }
|
7
7
|
|
8
|
-
def api_response(ids, offset)
|
8
|
+
def api_response(ids, offset, options = {})
|
9
9
|
records = ids.map { |i| { id: i } }
|
10
10
|
{
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
options.fetch(:items_key, :items) => records,
|
12
|
+
options.fetch(:total_key, :total) => total,
|
13
|
+
options.fetch(:limit_key, :limit) => limit,
|
14
|
+
options.fetch(:pagination_key, :offset) => offset
|
15
15
|
}.to_json
|
16
16
|
end
|
17
17
|
|
@@ -63,4 +63,31 @@ describe LHS::Collection do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
context 'configured pagination' do
|
68
|
+
before(:each) do
|
69
|
+
class Record < LHS::Record
|
70
|
+
endpoint ':datastore/:campaign_id/feedbacks'
|
71
|
+
endpoint ':datastore/feedbacks'
|
72
|
+
configuration items_key: 'docs', limit_key: 'size', pagination_key: 'start', pagination_strategy: 'start', total_key: 'totalResults'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:options) { { items_key: 'docs', limit_key: 'size', pagination_key: 'start', total_key: 'totalResults' } }
|
77
|
+
|
78
|
+
it 'capable to do batch processing with configured pagination' do
|
79
|
+
stub_request(:get, "#{datastore}/feedbacks?size=230&start=1").to_return(status: 200, body: api_response((1..100).to_a, 1, options))
|
80
|
+
stub_request(:get, "#{datastore}/feedbacks?size=100&start=101").to_return(status: 200, body: api_response((101..200).to_a, 101, options))
|
81
|
+
stub_request(:get, "#{datastore}/feedbacks?size=100&start=201").to_return(status: 200, body: api_response((201..300).to_a, 201, options))
|
82
|
+
stub_request(:get, "#{datastore}/feedbacks?size=100&start=301").to_return(status: 200, body: api_response((301..400).to_a, 301, options))
|
83
|
+
stub_request(:get, "#{datastore}/feedbacks?size=100&start=401").to_return(status: 200, body: api_response((401..total).to_a, 401, options))
|
84
|
+
length = 0
|
85
|
+
Record.find_in_batches(batch_size: 230) do |records|
|
86
|
+
length += records.length
|
87
|
+
expect(records).to be_kind_of Record
|
88
|
+
expect(records._proxy).to be_kind_of LHS::Collection
|
89
|
+
end
|
90
|
+
expect(length).to eq total
|
91
|
+
end
|
92
|
+
end
|
66
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.6.
|
4
|
+
version: 5.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06
|
11
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|