standard_pagination 0.1.0 → 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: d60e0bc850fa3f5f3efdfc07c355de37b9c4d569d86f05ddd47962c20e4a1636
4
- data.tar.gz: dd47c304ed63c9f5a6df5f7c69a07eff5ef32fe495b372fe1cc0b1b072af52e7
3
+ metadata.gz: c8213902bdeb4fed07cf6c759eb52fc064a4f62154a25a7c92dafba705232a7d
4
+ data.tar.gz: 6fc78271275b84da5b601836cd6b03e100545b43a8c79ffc6ef8ea30a761e139
5
5
  SHA512:
6
- metadata.gz: f07018870793cd23b22a8043c8e0aa34977dbf46547355922e90855135ee36fa6fb60cccc452f4bebff45ca4667cdd9456e4a176f5f922bde78dfc977dbc407e
7
- data.tar.gz: 5a0762267cadaf3fad98ad90b2dd7cef1dfee4862bc66ee8d4b1dcf0c1e5966e8384afebe1063c50f434c1b0d073add3b47d39e1c131096cf170a5fa9d468c5e
6
+ metadata.gz: 41c6e457018dd8e2c9d320cd7ea298a7c8812cefd64ff47d1828d12851cdcbe6e45da01add2a7cf70b8cda166789b4d851dec5812cc6f8fb8443e6737f914f50
7
+ data.tar.gz: 631d2e4e9ad5bd57077073417663f19e709912171918b6dd39feaf8370848f7d9fb6ac8ea228ec41b5fe334a992393593a47b622c450c6bfbe7204d78c6efd4d
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ 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
+
15
+ ## [0.1.1] - 2026-10-25
16
+
17
+ ### Fixed
18
+ - `Controller#paginate` raised `NoMethodError` (`select_values` for Array) when given an in-memory Array, such as an assembled audit timeline. The inline-DISTINCT count check added late in 0.1.0 assumed an ActiveRecord relation. Arrays paginate again, and a spec covers them. Found while adopting the gem in fundbright-web.
19
+
10
20
  ## [0.1.0] - 2026-10-25
11
21
 
12
22
  ### Added
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
@@ -39,8 +39,11 @@ module StandardPagination
39
39
  relation.from_clause.empty?
40
40
  end
41
41
 
42
- # `select("DISTINCT category")` leaves distinct_value unset.
42
+ # `select("DISTINCT category")` leaves distinct_value unset. False for
43
+ # anything that isn't a relation (arrays, search results).
43
44
  def inline_distinct?(relation)
45
+ return false unless defined?(::ActiveRecord::Relation) && relation.is_a?(::ActiveRecord::Relation)
46
+
44
47
  relation.select_values.any? { |value| !value.is_a?(Symbol) && value.to_s.match?(/\bdistinct\b/i) }
45
48
  end
46
49
 
@@ -1,3 +1,3 @@
1
1
  module StandardPagination
2
- VERSION = "0.1.0"
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim