lhs 16.0.1 → 16.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/lhs/concerns/record/batch.rb +6 -4
- data/lib/lhs/version.rb +1 -1
- data/spec/record/find_each_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40c9a3c78d7e3f84b0652f9903eaba8b6f7312a7bd1b0e1a2f59100a6f296acb
|
4
|
+
data.tar.gz: a70e74d0de431175fe821751884d6b4eb60cc7e9bdd8c1237e906e41723c6b97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b5952d6ef6362ac7f9689a6c845469af65d8047228b267af4c28828adafdc776458af6a6562f395ae4dcc622b8462ef30f6b6e9c62a105a35ba9eb02f3d2b27
|
7
|
+
data.tar.gz: c554b8122c917cab6866bed3c081cebfc66d35971c10a085617fc0eec546d9e1e2542c7cfeae93400c1a07e4402398750317fcbd270f9b3d09a9bfe16f3eb9fe
|
data/README.md
CHANGED
@@ -2077,7 +2077,7 @@ In case an API does not provide pagination information in the repsponse data (li
|
|
2077
2077
|
`find_each` is a more fine grained way to process single records that are fetched in batches.
|
2078
2078
|
|
2079
2079
|
```ruby
|
2080
|
-
Record.find_each(start: 50, batch_size: 20, params: { has_reviews: true }) do |record|
|
2080
|
+
Record.find_each(start: 50, batch_size: 20, params: { has_reviews: true }, headers: { 'Authorization': 'Bearer 123' }) do |record|
|
2081
2081
|
# Iterates over each record. Starts with record no. 50 and fetches 20 records each batch.
|
2082
2082
|
record
|
2083
2083
|
break if record.some_attribute == some_value
|
@@ -2089,7 +2089,7 @@ end
|
|
2089
2089
|
`find_in_batches` is used by `find_each` and processes batches.
|
2090
2090
|
|
2091
2091
|
```ruby
|
2092
|
-
Record.find_in_batches(start: 50, batch_size: 20, params: { has_reviews: true }) do |records|
|
2092
|
+
Record.find_in_batches(start: 50, batch_size: 20, params: { has_reviews: true }, headers: { 'Authorization': 'Bearer 123' }) do |records|
|
2093
2093
|
# Iterates over multiple records (batch size is 20). Starts with record no. 50 and fetches 20 records each batch.
|
2094
2094
|
records
|
2095
2095
|
break if records.first.name == some_value
|
@@ -19,11 +19,13 @@ class LHS::Record
|
|
19
19
|
# Process batches of entries
|
20
20
|
def find_in_batches(options = {})
|
21
21
|
raise 'No block given' unless block_given?
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
options = options.dup
|
23
|
+
start = options.delete(:start) || 1
|
24
|
+
batch_size = options.delete(:batch_size) || LHS::Pagination::Base::DEFAULT_LIMIT
|
25
25
|
loop do # as suggested by Matz
|
26
|
-
|
26
|
+
options = options.dup
|
27
|
+
options[:params] = (options[:params] || {}).merge(limit_key(:parameter) => batch_size, pagination_key(:parameter) => start)
|
28
|
+
data = request(options)
|
27
29
|
batch_size = data._raw.dig(*limit_key(:body))
|
28
30
|
left = data._raw.dig(*total_key).to_i - data._raw.dig(*pagination_key(:body)).to_i - data._raw.dig(*limit_key(:body)).to_i
|
29
31
|
yield new(data)
|
data/lib/lhs/version.rb
CHANGED
@@ -41,5 +41,15 @@ describe LHS::Collection do
|
|
41
41
|
end
|
42
42
|
expect(count).to eq total
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'passes options to the requests made' do
|
46
|
+
request = stub_request(:get, "http://local.ch/v2/feedbacks?limit=100&offset=1")
|
47
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
48
|
+
.to_return(body: {
|
49
|
+
items: []
|
50
|
+
}.to_json)
|
51
|
+
Record.find_each(headers: { 'Authorization' => 'Bearer 123' }) { |record| }
|
52
|
+
expect(request).to have_been_made
|
53
|
+
end
|
44
54
|
end
|
45
55
|
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: 16.0
|
4
|
+
version: 16.1.0
|
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: 2018-
|
11
|
+
date: 2018-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|