promoted-ruby-client 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/dev.md +1 -1
- data/lib/promoted/ruby/client/pager.rb +25 -16
- data/lib/promoted/ruby/client/version.rb +1 -1
- 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: d2581fc859bd3a30b8460858e6ab95ef4be27724f60ac02cff4e15c4579ea833
|
4
|
+
data.tar.gz: e87f89c047284f62cdd8d1975aae5c464e096f32c752352f5d83820b8e922ea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98361d750d5bf3605b4acda0c974be206ae115fa973f8d4e57d723874d2fed40eb86b4f635ce22a502c5faf36e1e6ee12456f95b9d4fc8a5e763a0747393a20e
|
7
|
+
data.tar.gz: ebf6134571b25c908d9dba394286a31564517d0218d3d97975e5965a85d3607c91ff37f191cbb8d1dd2942bd9c47209cbb56315bd7ea3a4e92c92d5313220b36
|
data/Gemfile.lock
CHANGED
data/dev.md
CHANGED
@@ -11,4 +11,4 @@ bundle exec rspec
|
|
11
11
|
3. Modify `promoted-ruby-client.gemspec`'s push block.
|
12
12
|
4. Run `gem build promoted-ruby-client.gemspec` to generate `gem`.
|
13
13
|
5. Run `bundle exec rspec`. This updates `Gemfile.lock`.
|
14
|
-
6. Run (using new output) `gem push promoted-ruby-client-4.0.
|
14
|
+
6. Run (using new output) `gem push promoted-ruby-client-4.0.1.gem`
|
@@ -13,24 +13,28 @@ module Promoted
|
|
13
13
|
class Pager
|
14
14
|
def validate_paging(insertions, retrieval_insertion_offset, paging)
|
15
15
|
if paging && paging[:offset]
|
16
|
-
offset =
|
17
|
-
|
18
|
-
raise InvalidPagingError.new("Invalid page offset (insertion size #{insertions.length}, offset #{offset})", [])
|
19
|
-
end
|
20
|
-
if offset < retrieval_insertion_offset
|
21
|
-
raise InvalidPagingError.new("Invalid page offset (retrieval_insertion_offset #{retrieval_insertion_offset}, offset #{offset})", [])
|
22
|
-
end
|
16
|
+
offset, retrieval_insertion_offset, index = _sanitize_offsets(retrieval_insertion_offset, paging)
|
17
|
+
_validate_paging(insertions, retrieval_insertion_offset, offset, index)
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
def _sanitize_offsets(retrieval_insertion_offset, paging)
|
22
|
+
offset = [0, paging[:offset]].max
|
23
|
+
retrieval_insertion_offset = [0, retrieval_insertion_offset].max
|
24
|
+
index = [0, offset - retrieval_insertion_offset].max
|
25
|
+
return [offset, retrieval_insertion_offset, index]
|
26
|
+
end
|
27
|
+
|
28
|
+
def _validate_paging(insertions, retrieval_insertion_offset, offset, index)
|
29
|
+
if offset < retrieval_insertion_offset
|
30
|
+
raise InvalidPagingError.new("Invalid page offset (retrieval_insertion_offset #{retrieval_insertion_offset}, offset #{offset})", [])
|
31
|
+
end
|
32
|
+
if index >= insertions.length
|
33
|
+
raise InvalidPagingError.new("Invalid page offset (insertion size #{insertions.length}, index #{index})", [])
|
32
34
|
end
|
35
|
+
end
|
33
36
|
|
37
|
+
def apply_paging(insertions, retrieval_insertion_offset, paging = nil)
|
34
38
|
if !paging
|
35
39
|
paging = {
|
36
40
|
:offset => 0,
|
@@ -38,9 +42,14 @@ module Promoted
|
|
38
42
|
}
|
39
43
|
end
|
40
44
|
|
41
|
-
offset =
|
42
|
-
|
43
|
-
|
45
|
+
offset, retrieval_insertion_offset, index = _sanitize_offsets(retrieval_insertion_offset, paging)
|
46
|
+
|
47
|
+
begin
|
48
|
+
_validate_paging(insertions, retrieval_insertion_offset, offset, index)
|
49
|
+
rescue InvalidPagingError => err
|
50
|
+
# This is invalid input, stop it before it goes to the server.
|
51
|
+
return err.default_insertions_page
|
52
|
+
end
|
44
53
|
|
45
54
|
size = paging[:size]
|
46
55
|
if size <= 0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promoted-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scottmcmaster
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|