standard_pagination 0.1.1 → 0.1.2
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/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/standard_pagination/config.rb +2 -1
- data/lib/standard_pagination/controller.rb +8 -2
- data/lib/standard_pagination/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8213902bdeb4fed07cf6c759eb52fc064a4f62154a25a7c92dafba705232a7d
|
|
4
|
+
data.tar.gz: 6fc78271275b84da5b601836cd6b03e100545b43a8c79ffc6ef8ea30a761e139
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41c6e457018dd8e2c9d320cd7ea298a7c8812cefd64ff47d1828d12851cdcbe6e45da01add2a7cf70b8cda166789b4d851dec5812cc6f8fb8443e6737f914f50
|
|
7
|
+
data.tar.gz: 631d2e4e9ad5bd57077073417663f19e709912171918b6dd39feaf8370848f7d9fb6ac8ea228ec41b5fe334a992393593a47b622c450c6bfbe7204d78c6efd4d
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.2] - 2026-10-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `config.limit_key` accepts an Array of aliases, e.g. `%w[limit per_page]`; the first one the request sends wins. For APIs whose clients use both (luminality-web). The out-of-range redirect drops all of them. (Meant for 0.1.1, but that PR auto-merged before this commit landed.)
|
|
14
|
+
|
|
10
15
|
## [0.1.1] - 2026-10-25
|
|
11
16
|
|
|
12
17
|
### Fixed
|
data/README.md
CHANGED
|
@@ -45,7 +45,7 @@ Delete `max_limit` (or `client_limit`) from `config/initializers/pagy.rb`. Leave
|
|
|
45
45
|
StandardPagination.configure do |c|
|
|
46
46
|
c.default_limit = 20 # rows when a call site passes no limit:
|
|
47
47
|
c.max_limit = 100 # cap on a client-chosen page size
|
|
48
|
-
c.limit_key = "limit" # param a client sets it with
|
|
48
|
+
c.limit_key = "limit" # param a client sets it with; an Array accepts aliases, e.g. %w[limit per_page]
|
|
49
49
|
c.client_limit_formats = %i[json]
|
|
50
50
|
c.tiebreak = true
|
|
51
51
|
c.raise_range_error = true
|
|
@@ -4,7 +4,8 @@ module StandardPagination
|
|
|
4
4
|
attr_accessor :default_limit
|
|
5
5
|
# Largest page size a client may request when client limits are on.
|
|
6
6
|
attr_accessor :max_limit
|
|
7
|
-
# Request param a client sets the page size with (when allowed).
|
|
7
|
+
# Request param a client sets the page size with (when allowed). An Array
|
|
8
|
+
# accepts aliases; the first one the request sends wins.
|
|
8
9
|
attr_accessor :limit_key
|
|
9
10
|
# Formats for which `paginate` honours the client's page size by default.
|
|
10
11
|
# HTML pages keep the size the call site chose.
|
|
@@ -96,12 +96,18 @@ module StandardPagination
|
|
|
96
96
|
cap = pagination_client_limit_cap(client_limit)
|
|
97
97
|
return limit unless cap
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
# The first configured key the request sends wins.
|
|
100
|
+
key = pagination_limit_keys.find { |candidate| params[candidate].present? }
|
|
101
|
+
requested = key ? params[key].to_s : ""
|
|
100
102
|
return limit unless requested.match?(/\A\d+\z/) && requested.to_i.positive?
|
|
101
103
|
|
|
102
104
|
[ requested.to_i, cap ].min
|
|
103
105
|
end
|
|
104
106
|
|
|
107
|
+
def pagination_limit_keys
|
|
108
|
+
Array(StandardPagination.config.limit_key).map(&:to_s)
|
|
109
|
+
end
|
|
110
|
+
|
|
105
111
|
def pagination_client_limit_cap(client_limit)
|
|
106
112
|
client_limit = pagination_client_limit_format? if client_limit.nil?
|
|
107
113
|
|
|
@@ -144,7 +150,7 @@ module StandardPagination
|
|
|
144
150
|
if last_page
|
|
145
151
|
query[page_key] = last_page
|
|
146
152
|
else
|
|
147
|
-
query = query.except((options[:limit_key] || Pagy::DEFAULT[:limit_key]).to_s,
|
|
153
|
+
query = query.except((options[:limit_key] || Pagy::DEFAULT[:limit_key]).to_s, *pagination_limit_keys)
|
|
148
154
|
# Nothing left to drop: the bad option came from the call site or a
|
|
149
155
|
# param this gem doesn't know, so redirecting would only repeat it.
|
|
150
156
|
return head(:bad_request) if query == original
|