lhs 20.1.3.pre.paginationfix.2 → 20.1.3.pre.paginationfix.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77f78ba0588ecc1b8e7d65c397a247459ab9caa2dfb43239635bf10680277e1e
4
- data.tar.gz: a4e0e1e31dbe6346e648ec4b0406055688abc1487becc743e419cc72c3b6a07d
3
+ metadata.gz: b9284aed364b9d0b32bd9341399c4c8309aa3438c4d6e073b89a7d4f3fcaab21
4
+ data.tar.gz: d3c50128acf732d233b61d2930f22a38d48102dca92fb13ab2f2f88a03108767
5
5
  SHA512:
6
- metadata.gz: '012237879f1dbd65316592604126fa3a2593c5c6500801a01a3b6f09f3ffbbb9cd9060e974604549139b699a800b0c9185c32b4b0e926b5f93915f9edae5be72'
7
- data.tar.gz: c291587ba6fd626dd17ac7c470fb1f8ccd55a8926bb395773a63902b72c432a881c4934e53d249fcf7cf3b4142fd63213d6bbab3cce021bef4246ccbe0925342
6
+ metadata.gz: f75419036051feb2e65f155a59dfedf1364f2fb23f2f97bab4615fce6152ae8158f249a20f97308a4e8284c70180de920d5dc97ab13fbfd8f8876d2888aee7aa
7
+ data.tar.gz: 248054e48c2a757db5575c982f17356038d9d63d475f24fbd320c2bb1732481d7ff9ccc3c70b4baa50bef5c21701bec1ac2d0916ed917fdab30f58737d7472cf
@@ -23,12 +23,12 @@ module LHS::Pagination
23
23
  alias count total
24
24
 
25
25
  def limit
26
- limit_value = data._raw.dig(*_record.limit_key(:body))
27
- requested_limit = data._request.params.dig(*_record.limit_key(:params))
28
- if requested_limit && limit_value && limit_value < requested_limit
26
+ response_limit = data._raw.dig(*_record.limit_key(:body))
27
+ requested_limit = data._request.params.dig(*_record.limit_key(:params)).to_i if data&._request&.params.present?
28
+ if requested_limit && response_limit && last_page?(response_limit, requested_limit) && response_limit < requested_limit
29
29
  requested_limit
30
30
  else
31
- limit_value || DEFAULT_LIMIT
31
+ response_limit || DEFAULT_LIMIT
32
32
  end
33
33
  end
34
34
 
@@ -53,6 +53,10 @@ module LHS::Pagination
53
53
  # should be implemented in subclass (optional)
54
54
  end
55
55
 
56
+ def last_page?
57
+ raise 'to be implemented in subclass'
58
+ end
59
+
56
60
  def first_page
57
61
  1
58
62
  end
@@ -12,6 +12,10 @@ class LHS::Pagination::Offset < LHS::Pagination::Base
12
12
  self.class.next_offset(offset, limit, step)
13
13
  end
14
14
 
15
+ def last_page?(response_limit, requested_limit)
16
+ offset + response_limit >= total
17
+ end
18
+
15
19
  def self.page_to_offset(page, limit = DEFAULT_LIMIT)
16
20
  (page.to_i - 1) * limit.to_i
17
21
  end
@@ -8,6 +8,10 @@ class LHS::Pagination::Page < LHS::Pagination::Base
8
8
  offset
9
9
  end
10
10
 
11
+ def last_page?(response_limit, requested_limit)
12
+ (offset-1 * requested_limit) + response_limit >= total
13
+ end
14
+
11
15
  def next_offset(step = 1)
12
16
  self.class.next_offset(current_page, limit, step)
13
17
  end
@@ -12,6 +12,10 @@ class LHS::Pagination::Start < LHS::Pagination::Base
12
12
  self.class.next_offset(offset, limit, step)
13
13
  end
14
14
 
15
+ def last_page?(response_limit, requested_limit)
16
+ offset + response_limit > total
17
+ end
18
+
15
19
  def self.page_to_offset(page, limit = DEFAULT_LIMIT)
16
20
  (page.to_i - 1) * limit.to_i + 1
17
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '20.1.3.pre.paginationfix.2'
4
+ VERSION = '20.1.3.pre.paginationfix.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 20.1.3.pre.paginationfix.2
4
+ version: 20.1.3.pre.paginationfix.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors