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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4d336aef96b116acbe2e611279e9ccefe5efce88063d5c530fb669b32383d10
4
- data.tar.gz: 6df512d099b5a5b9414b2672847585db2118825b87c178b923da26ba2cb610e8
3
+ metadata.gz: d2581fc859bd3a30b8460858e6ab95ef4be27724f60ac02cff4e15c4579ea833
4
+ data.tar.gz: e87f89c047284f62cdd8d1975aae5c464e096f32c752352f5d83820b8e922ea4
5
5
  SHA512:
6
- metadata.gz: 7375f08d88303d6de8eefaf3a4b7e2b80333f15e8b709781c4884aee54d84c9d64b6bdc834c4a5c53f1f426a04a5aed9752cc7ceba78d6015f100d7ee6096e0c
7
- data.tar.gz: 2cdff05db0a989331ca56e0f18716f53e635ea7d000d685275693b21445a313763e2001827b201ec2863173eb52f54744b50177f824ae7a0d44a85f975105e5e
6
+ metadata.gz: 98361d750d5bf3605b4acda0c974be206ae115fa973f8d4e57d723874d2fed40eb86b4f635ce22a502c5faf36e1e6ee12456f95b9d4fc8a5e763a0747393a20e
7
+ data.tar.gz: ebf6134571b25c908d9dba394286a31564517d0218d3d97975e5965a85d3607c91ff37f191cbb8d1dd2942bd9c47209cbb56315bd7ea3a4e92c92d5313220b36
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- promoted-ruby-client (4.0.0)
4
+ promoted-ruby-client (4.0.1)
5
5
  concurrent-ruby (~> 1)
6
6
  faraday (>= 0.9.0)
7
7
  faraday_middleware (>= 0.9.0)
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.0.gem`
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 = [0, paging[:offset]].max
17
- if offset >= insertions.length
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 apply_paging(insertions, retrieval_insertion_offset, paging = nil)
27
- begin
28
- validate_paging(insertions, retrieval_insertion_offset, paging)
29
- rescue InvalidPagingError => err
30
- # This is invalid input, stop it before it goes to the server.
31
- return err.default_insertions_page
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 = [0, paging[:offset]].max
42
- retrieval_insertion_offset = [0, retrieval_insertion_offset].max
43
- index = [0, offset - retrieval_insertion_offset].max
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
@@ -1,7 +1,7 @@
1
1
  module Promoted
2
2
  module Ruby
3
3
  module Client
4
- VERSION = "4.0.0"
4
+ VERSION = "4.0.1"
5
5
  SERVER_VERSION = "rb." + VERSION
6
6
  end
7
7
  end
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.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-17 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday