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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 149b70a719e0da5a83ca318611fd7a97c8c01678022e9ca52831b2007285b138
4
- data.tar.gz: 6be9f28d0f29f6179a4a38abcebad5e985ad992a35cf08d5c0eeb1746b2edf35
3
+ metadata.gz: c8213902bdeb4fed07cf6c759eb52fc064a4f62154a25a7c92dafba705232a7d
4
+ data.tar.gz: 6fc78271275b84da5b601836cd6b03e100545b43a8c79ffc6ef8ea30a761e139
5
5
  SHA512:
6
- metadata.gz: 6dc0d679a00cea8898d0da4d9369c38238ffff057eb4e1e691c82f764ce781f9690083d6ce1873fe2c9a0f2dc4409e3da5c44bc4219a092892bd253340a16e4e
7
- data.tar.gz: 4f345dc7fb354212d8a4c9b02f950449fe80a8c8c99dee233bb149f770445ae0a9906e82f1443edd22b9118662c2f0a7d3ed51f3f5b6a133e21c803bc5a7b928
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 ("per_page" in luminality)
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
- requested = params[StandardPagination.config.limit_key].to_s
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, StandardPagination.config.limit_key)
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
@@ -1,3 +1,3 @@
1
1
  module StandardPagination
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim