diff --git a/.github/ISSUE_TEMPLATE/Code.yml b/.github/ISSUE_TEMPLATE/Code.yml index c56b54558..dfc4d6071 100644 --- a/.github/ISSUE_TEMPLATE/Code.yml +++ b/.github/ISSUE_TEMPLATE/Code.yml @@ -19,7 +19,7 @@ body: attributes: label: 👀 Before submitting... options: - - label: I upgraded to pagy version 9.2.2 + - label: I upgraded to pagy version 9.3.0 required: true - label: I searched through the [Documentation](https://ddnexus.github.io/pagy/) required: true diff --git a/.github/latest_release_body.md b/.github/latest_release_body.md index 5f8deb029..84f2d1f36 100644 --- a/.github/latest_release_body.md +++ b/.github/latest_release_body.md @@ -6,12 +6,11 @@ - See the [Changelog](https://ddnexus.github.io/pagy/changelog) for possible breaking changes -### Changes in 9.2.2 +### Changes in 9.3.0 -- Replace inline templates with template block in sinatra apps -- Replace the rails calendar app with a sinatra app -- Add PagyApps::INDEX +- Remove the :typecast_latest variable +- Add the :jsonify_keyset_attributes variable to override the encoding (#749) [CHANGELOG](https://ddnexus.github.io/pagy/changelog) diff --git a/.rubocop.yml b/.rubocop.yml index 5f3144685..5e829674d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,6 +22,9 @@ Layout/LineLength: Exclude: - test/**/* +Layout/BeginEndAlignment: + EnforcedStyleAlignWith: begin + Layout/ExtraSpacing: AllowForAlignment: Enabled: true diff --git a/CHANGELOG.md b/CHANGELOG.md index db7cae6bd..297a8097f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,11 @@ If you upgrade from version `< 9.0.0` see the following: - `:after_latest` keyset variable: use `:filter_newest`
+## Version 9.3.0 + +- Remove the :typecast_latest variable +- Add the :jsonify_keyset_attributes variable to override the encoding (#749) + ## Version 9.2.2 - Replace inline templates with template block in sinatra apps diff --git a/Gemfile.lock b/Gemfile.lock index 798045990..2c909bcf9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: gem specs: - pagy (9.2.2) + pagy (9.3.0) GEM remote: https://rubygems.org/ @@ -125,7 +125,7 @@ GEM irb (1.14.1) rdoc (>= 4.0.0) reline (>= 0.4.2) - json (2.8.1) + json (2.8.2) language_server-protocol (3.17.0.3) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) @@ -197,7 +197,7 @@ GEM rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (2.2.0) + rackup (2.2.1) rack (>= 3) rails (8.0.0) actioncable (= 8.0.0) @@ -241,7 +241,7 @@ GEM rematch (3.1.0) rerun (0.14.0) listen (~> 3.0) - rouge (4.5.0) + rouge (4.5.1) rubocop (1.68.0) json (~> 2.3) language_server-protocol (>= 3.17.0) @@ -252,14 +252,14 @@ GEM rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.34.1) + rubocop-ast (1.36.1) parser (>= 3.3.1.0) rubocop-minitest (0.36.0) rubocop (>= 1.61, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-packaging (0.5.2) rubocop (>= 1.33, < 2.0) - rubocop-performance (1.22.1) + rubocop-performance (1.23.0) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-rake (0.6.0) @@ -298,7 +298,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) - uri (1.0.1) + uri (1.0.2) useragent (0.16.10) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) diff --git a/README.md b/README.md index 1bfa77dd8..b05e6e035 100644 --- a/README.md +++ b/README.md @@ -282,7 +282,7 @@ See also the [How To Page](https://ddnexus.github.io/pagy/docs/how-to) -[](https://github.com/ddnexus/pagy/commits?author=ddnexus)[](https://github.com/ddnexus/pagy/commits?author=benkoshy)[](https://github.com/ddnexus/pagy/commits?author=grosser)[](https://github.com/ddnexus/pagy/commits?author=Earlopain)[](https://github.com/ddnexus/pagy/commits?author=workgena)[](https://github.com/ddnexus/pagy/commits?author=espen)[](https://github.com/ddnexus/pagy/commits?author=enzinia)[](https://github.com/ddnexus/pagy/commits?author=sunny)[](https://github.com/ddnexus/pagy/commits?author=molfar)[](https://github.com/ddnexus/pagy/commits?author=bquorning)[](https://github.com/ddnexus/pagy/commits?author=djpremier)[](https://github.com/ddnexus/pagy/commits?author=747)[](https://github.com/ddnexus/pagy/commits?author=tersor)[](https://github.com/ddnexus/pagy/commits?author=thomasklemm)[](https://github.com/ddnexus/pagy/commits?author=gamafranco)[](https://github.com/ddnexus/pagy/commits?author=tiagotex)[](https://github.com/ddnexus/pagy/commits?author=wimdavies)[](https://github.com/ddnexus/pagy/commits?author=renshuki)[](https://github.com/ddnexus/pagy/commits?author=berniechiu)[](https://github.com/ddnexus/pagy/commits?author=ashmaroli)[](https://github.com/ddnexus/pagy/commits?author=cseelus)[](https://github.com/ddnexus/pagy/commits?author=sabljak)[](https://github.com/ddnexus/pagy/commits?author=petergoldstein)[](https://github.com/ddnexus/pagy/commits?author=rainerborene)[](https://github.com/ddnexus/pagy/commits?author=rbngzlv)[](https://github.com/ddnexus/pagy/commits?author=simonneutert)[](https://github.com/ddnexus/pagy/commits?author=artplan1)[](https://github.com/ddnexus/pagy/commits?author=serghost)[](https://github.com/ddnexus/pagy/commits?author=Tolchi)[](https://github.com/ddnexus/pagy/commits?author=rogermarlow)[](https://github.com/ddnexus/pagy/commits?author=yenshirak)[](https://github.com/ddnexus/pagy/commits?author=rafaelmontas)[](https://github.com/ddnexus/pagy/commits?author=rafaeelaudibert)[](https://github.com/ddnexus/pagy/commits?author=pedrocarmona)[](https://github.com/ddnexus/pagy/commits?author=olleolleolle)[](https://github.com/ddnexus/pagy/commits?author=olieidel)[](https://github.com/ddnexus/pagy/commits?author=okuramasafumi)[](https://github.com/ddnexus/pagy/commits?author=WilliamHorel)[](https://github.com/ddnexus/pagy/commits?author=woller)[](https://github.com/ddnexus/pagy/commits?author=sk8higher)[](https://github.com/ddnexus/pagy/commits?author=muhammadnawzad)[](https://github.com/ddnexus/pagy/commits?author=ronald)[](https://github.com/ddnexus/pagy/commits?author=achmiral)[](https://github.com/ddnexus/pagy/commits?author=mauro-ni)[](https://github.com/ddnexus/pagy/commits?author=borama)[](https://github.com/ddnexus/pagy/commits?author=creativetags)[](https://github.com/ddnexus/pagy/commits?author=mcary)[](https://github.com/ddnexus/pagy/commits?author=marckohlbrugge)[](https://github.com/ddnexus/pagy/commits?author=fluser)[](https://github.com/ddnexus/pagy/commits?author=maful)[](https://github.com/ddnexus/pagy/commits?author=AngelGuerra)[](https://github.com/ddnexus/pagy/commits?author=tr4b4nt)[](https://github.com/ddnexus/pagy/commits?author=tiejianluo)[](https://github.com/ddnexus/pagy/commits?author=szTheory)[](https://github.com/ddnexus/pagy/commits?author=smoothdvd)[](https://github.com/ddnexus/pagy/commits?author=rhodes-david)[](https://github.com/ddnexus/pagy/commits?author=radinreth)[](https://github.com/ddnexus/pagy/commits?author=pranavbabu)[](https://github.com/ddnexus/pagy/commits?author=okliv)[](https://github.com/ddnexus/pagy/commits?author=nedimdz)[](https://github.com/ddnexus/pagy/commits?author=msdundar)[](https://github.com/ddnexus/pagy/commits?author=m-abdurrehman)[](https://github.com/ddnexus/pagy/commits?author=dwieringa)[](https://github.com/ddnexus/pagy/commits?author=jyuvaraj03)[](https://github.com/ddnexus/pagy/commits?author=YutoYasunaga)[](https://github.com/ddnexus/pagy/commits?author=iamyujinwon)[](https://github.com/ddnexus/pagy/commits?author=yhk1038)[](https://github.com/ddnexus/pagy/commits?author=ya-s-u)[](https://github.com/ddnexus/pagy/commits?author=yshmarov)[](https://github.com/ddnexus/pagy/commits?author=thattimc)[](https://github.com/ddnexus/pagy/commits?author=thomaschauffour)[](https://github.com/ddnexus/pagy/commits?author=snkashis)[](https://github.com/ddnexus/pagy/commits?author=sliminas)[](https://github.com/ddnexus/pagy/commits?author=LuukvH)[](https://github.com/ddnexus/pagy/commits?author=Federico-G)[](https://github.com/ddnexus/pagy/commits?author=egimenos)[](https://github.com/ddnexus/pagy/commits?author=elliotlarson)[](https://github.com/ddnexus/pagy/commits?author=hungdiep97)[](https://github.com/ddnexus/pagy/commits?author=davidwessman)[](https://github.com/ddnexus/pagy/commits?author=david-a-wheeler)[](https://github.com/ddnexus/pagy/commits?author=daniel-rikowski)[](https://github.com/ddnexus/pagy/commits?author=connie-feng)[](https://github.com/ddnexus/pagy/commits?author=MrMoins)[](https://github.com/ddnexus/pagy/commits?author=excid3)[](https://github.com/ddnexus/pagy/commits?author=cellvinchung)[](https://github.com/ddnexus/pagy/commits?author=brunoocasali)[](https://github.com/ddnexus/pagy/commits?author=branson-simplethread)[](https://github.com/ddnexus/pagy/commits?author=BrandonKlotz)[](https://github.com/ddnexus/pagy/commits?author=benjaminwols)[](https://github.com/ddnexus/pagy/commits?author=Atul9)[](https://github.com/ddnexus/pagy/commits?author=amenon)[](https://github.com/ddnexus/pagy/commits?author=artinboghosian)[](https://github.com/ddnexus/pagy/commits?author=antonzaharia)[](https://github.com/ddnexus/pagy/commits?author=PyrinAndrii)[](https://github.com/ddnexus/pagy/commits?author=andrew)[](https://github.com/ddnexus/pagy/commits?author=AliOsm)[](https://github.com/ddnexus/pagy/commits?author=AbelToy)[](https://github.com/ddnexus/pagy/commits?author=loed-idzinga)[](https://github.com/ddnexus/pagy/commits?author=epeirce)[](https://github.com/ddnexus/pagy/commits?author=kobusjoubert) +[](https://github.com/ddnexus/pagy/commits?author=ddnexus)[](https://github.com/ddnexus/pagy/commits?author=benkoshy)[](https://github.com/ddnexus/pagy/commits?author=grosser)[](https://github.com/ddnexus/pagy/commits?author=Earlopain)[](https://github.com/ddnexus/pagy/commits?author=workgena)[](https://github.com/ddnexus/pagy/commits?author=espen)[](https://github.com/ddnexus/pagy/commits?author=enzinia)[](https://github.com/ddnexus/pagy/commits?author=sunny)[](https://github.com/ddnexus/pagy/commits?author=molfar)[](https://github.com/ddnexus/pagy/commits?author=bquorning)[](https://github.com/ddnexus/pagy/commits?author=djpremier)[](https://github.com/ddnexus/pagy/commits?author=747)[](https://github.com/ddnexus/pagy/commits?author=tersor)[](https://github.com/ddnexus/pagy/commits?author=thomasklemm)[](https://github.com/ddnexus/pagy/commits?author=gamafranco)[](https://github.com/ddnexus/pagy/commits?author=tiagotex)[](https://github.com/ddnexus/pagy/commits?author=wimdavies)[](https://github.com/ddnexus/pagy/commits?author=renshuki)[](https://github.com/ddnexus/pagy/commits?author=berniechiu)[](https://github.com/ddnexus/pagy/commits?author=ashmaroli)[](https://github.com/ddnexus/pagy/commits?author=cseelus)[](https://github.com/ddnexus/pagy/commits?author=sabljak)[](https://github.com/ddnexus/pagy/commits?author=petergoldstein)[](https://github.com/ddnexus/pagy/commits?author=rainerborene)[](https://github.com/ddnexus/pagy/commits?author=rbngzlv)[](https://github.com/ddnexus/pagy/commits?author=simonneutert)[](https://github.com/ddnexus/pagy/commits?author=artplan1)[](https://github.com/ddnexus/pagy/commits?author=serghost)[](https://github.com/ddnexus/pagy/commits?author=Tolchi)[](https://github.com/ddnexus/pagy/commits?author=rogermarlow)[](https://github.com/ddnexus/pagy/commits?author=yenshirak)[](https://github.com/ddnexus/pagy/commits?author=rafaelmontas)[](https://github.com/ddnexus/pagy/commits?author=rafaeelaudibert)[](https://github.com/ddnexus/pagy/commits?author=pedrocarmona)[](https://github.com/ddnexus/pagy/commits?author=olleolleolle)[](https://github.com/ddnexus/pagy/commits?author=olieidel)[](https://github.com/ddnexus/pagy/commits?author=okuramasafumi)[](https://github.com/ddnexus/pagy/commits?author=WilliamHorel)[](https://github.com/ddnexus/pagy/commits?author=woller)[](https://github.com/ddnexus/pagy/commits?author=sk8higher)[](https://github.com/ddnexus/pagy/commits?author=muhammadnawzad)[](https://github.com/ddnexus/pagy/commits?author=ronald)[](https://github.com/ddnexus/pagy/commits?author=achmiral)[](https://github.com/ddnexus/pagy/commits?author=mauro-ni)[](https://github.com/ddnexus/pagy/commits?author=borama)[](https://github.com/ddnexus/pagy/commits?author=creativetags)[](https://github.com/ddnexus/pagy/commits?author=mcary)[](https://github.com/ddnexus/pagy/commits?author=marckohlbrugge)[](https://github.com/ddnexus/pagy/commits?author=fluser)[](https://github.com/ddnexus/pagy/commits?author=maful)[](https://github.com/ddnexus/pagy/commits?author=AngelGuerra)[](https://github.com/ddnexus/pagy/commits?author=tr4b4nt)[](https://github.com/ddnexus/pagy/commits?author=tiejianluo)[](https://github.com/ddnexus/pagy/commits?author=szTheory)[](https://github.com/ddnexus/pagy/commits?author=smoothdvd)[](https://github.com/ddnexus/pagy/commits?author=rhodes-david)[](https://github.com/ddnexus/pagy/commits?author=radinreth)[](https://github.com/ddnexus/pagy/commits?author=pranavbabu)[](https://github.com/ddnexus/pagy/commits?author=okliv)[](https://github.com/ddnexus/pagy/commits?author=nedimdz)[](https://github.com/ddnexus/pagy/commits?author=msdundar)[](https://github.com/ddnexus/pagy/commits?author=m-abdurrehman)[](https://github.com/ddnexus/pagy/commits?author=dwieringa)[](https://github.com/ddnexus/pagy/commits?author=jyuvaraj03)[](https://github.com/ddnexus/pagy/commits?author=YutoYasunaga)[](https://github.com/ddnexus/pagy/commits?author=iamyujinwon)[](https://github.com/ddnexus/pagy/commits?author=yhk1038)[](https://github.com/ddnexus/pagy/commits?author=ya-s-u)[](https://github.com/ddnexus/pagy/commits?author=yshmarov)[](https://github.com/ddnexus/pagy/commits?author=thattimc)[](https://github.com/ddnexus/pagy/commits?author=thomaschauffour)[](https://github.com/ddnexus/pagy/commits?author=snkashis)[](https://github.com/ddnexus/pagy/commits?author=sliminas)[](https://github.com/ddnexus/pagy/commits?author=LuukvH)[](https://github.com/ddnexus/pagy/commits?author=Federico-G)[](https://github.com/ddnexus/pagy/commits?author=egimenos)[](https://github.com/ddnexus/pagy/commits?author=elliotlarson)[](https://github.com/ddnexus/pagy/commits?author=hungdiep97)[](https://github.com/ddnexus/pagy/commits?author=davidwessman)[](https://github.com/ddnexus/pagy/commits?author=david-a-wheeler)[](https://github.com/ddnexus/pagy/commits?author=daniel-rikowski)[](https://github.com/ddnexus/pagy/commits?author=connie-feng)[](https://github.com/ddnexus/pagy/commits?author=MrMoins)[](https://github.com/ddnexus/pagy/commits?author=excid3)[](https://github.com/ddnexus/pagy/commits?author=cellvinchung)[](https://github.com/ddnexus/pagy/commits?author=brunoocasali)[](https://github.com/ddnexus/pagy/commits?author=branson-simplethread)[](https://github.com/ddnexus/pagy/commits?author=BrandonKlotz)[](https://github.com/ddnexus/pagy/commits?author=benjaminwols)[](https://github.com/ddnexus/pagy/commits?author=Atul9)[](https://github.com/ddnexus/pagy/commits?author=amenon)[](https://github.com/ddnexus/pagy/commits?author=artinboghosian)[](https://github.com/ddnexus/pagy/commits?author=antonzaharia)[](https://github.com/ddnexus/pagy/commits?author=PyrinAndrii)[](https://github.com/ddnexus/pagy/commits?author=andrew)[](https://github.com/ddnexus/pagy/commits?author=AliOsm)[](https://github.com/ddnexus/pagy/commits?author=AbelToy)[](https://github.com/ddnexus/pagy/commits?author=loed-idzinga)[](https://github.com/ddnexus/pagy/commits?author=epeirce)[](https://github.com/ddnexus/pagy/commits?author=kobusjoubert)
diff --git a/bun.lockb b/bun.lockb index fe2bc013c..99e2410c0 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docs/api/keyset.md b/docs/api/keyset.md index 36d721289..a9ec4502b 100644 --- a/docs/api/keyset.md +++ b/docs/api/keyset.md @@ -114,7 +114,7 @@ If you need a specific order: ### How Pagy::Keyset works - You pass an `uniquely ordered` `set` and `Pagy::Keyset` queries the page of records. -- It keeps track of the `latest` fetched record by encoding its `keyset` attributes into the `page` query string param of the +- It keeps track of the `latest` fetched record by encoding its `keyset` attributes into the `page` query string param of the `next` URL. - At each request, the `:page` is decoded and used to prepare a `when` clause that filters the newest records, and the `:limit` of records is pulled. @@ -181,21 +181,37 @@ end Pagy::Keyset(set, filter_newest:) ``` -==- `:typecast_latest` +==- `:jsonify_keyset_attributes` -A lambda to override the automatic typecasting of your ORM. For example: `SQLite` stores date and times as strings, and -the query interpolation may fail composing and comparing string dates. The `typecast_latest` is an effective last-resort -option when fixing the typecasting in your models and/or the data in your storage is not possible. +A lambda to override the generic json encoding of the `keyset` attributes. Use it when the generic `to_json` method would lose +some information when decoded. + +For example: `Time` objects may lose or round the fractional seconds through the +encoding/decoding cycle, causing the ordering to fail and thus creating all sort of unexpected behaviors (e.g. skipping or +repeating the same page, missing or duplicated records, etc.). Here is what you can do: ```ruby -typecast_latest = lambda do |latest| - latest[:timestamp] = Time.parse(latest[:timestamp]).strftime('%F %T') - latest +# Match the microsecods with the strings stored into the time columns of SQLite +jsonify_keyset_attributes = lambda do |attributes| + # Convert it to a string matching the stored value/format in SQLite DB + attributes[:created_at] = attributes[:created_at].strftime('%F %T.%6N') + attributes.to_json end -Pagy::Keyset(set, typecast_latest:) +Pagy::Keyset(set, jsonify_keyset_attributes:) ``` +!!! ActiveRecord alternative for time_precision + +With `ActiveRecord::Relation` set, you can fix the fractional seconds issue by just setting the `time_precision`: + +```ruby +ActiveSupport::JSON::Encoding.time_precision = 6 +``` +!!! + +_(Notice that it doesn't work with `Sequel::Dataset` sets)_ + === ## Attribute Readers @@ -206,7 +222,7 @@ Pagy::Keyset(set, typecast_latest:) ==- Records may repeat or be missing from successive pages -!!!danger Your set is not `uniquely ordered` +!!!danger The set may not be `uniquely ordered` ```rb # Neither columns are unique @@ -221,20 +237,18 @@ Product.order(:name, :production_date, :id) ``` !!! -!!!danger ... or you have a typecasting problem -Your ORM and the storage formats don't match for one or more columns. It's a common case with `SQLite` and Time columns. -They may have been stored as strings formatted differently than the default format used by your current ORM. +!!!danger You may have an encoding problem +The generic `to_json` method used to encode the `page` may lose some information when decoded !!!success - Check the actual executed DB query and the actual stored value - Identify the column that have a format that doesn't match with the keyset -- Fix the typecasting consistence of your ORM with your DB or consider using your custom typecasting with the - [:typecast_latest](#typecast-latest) variable +- Override the encoding with the [:jsonify_keyset_attributes](#jsonify-keyset-attributes) variable !!! - + ==- The order is OK, but the DB is still slow -!!!danger Most likely your index is not right, or your case needs a custom query +!!!danger Most likely the index is not right, or your case needs a custom query !!! Success diff --git a/gem/apps/calendar.ru b/gem/apps/calendar.ru index 549b46385..1f41dbf25 100644 --- a/gem/apps/calendar.ru +++ b/gem/apps/calendar.ru @@ -16,7 +16,7 @@ # URL # http://0.0.0.0:8000 -VERSION = '9.2.2' +VERSION = '9.3.0' # Bundle require 'bundler/inline' diff --git a/gem/apps/demo.ru b/gem/apps/demo.ru index d5c82107a..8f0ae9ee7 100644 --- a/gem/apps/demo.ru +++ b/gem/apps/demo.ru @@ -19,7 +19,7 @@ # URL # http://0.0.0.0:8000 -VERSION = '9.2.2' +VERSION = '9.3.0' # Bundle require 'bundler/inline' diff --git a/gem/apps/keyset_ar.ru b/gem/apps/keyset_ar.ru index d80a47883..6d151edf4 100644 --- a/gem/apps/keyset_ar.ru +++ b/gem/apps/keyset_ar.ru @@ -16,7 +16,7 @@ # URL # http://0.0.0.0:8000 -VERSION = '9.2.2' +VERSION = '9.3.0' # Bundle require 'bundler/inline' @@ -138,6 +138,10 @@ end # ActiveRecord setup require 'active_record' + +# Match the microsecods with the strings stored into the time columns of SQLite +# ActiveSupport::JSON::Encoding.time_precision = 6 + # Log output = ENV['APP_ENV'].equal?('showcase') ? IO::NULL : $stdout ActiveRecord::Base.logger = Logger.new(output) diff --git a/gem/apps/keyset_s.ru b/gem/apps/keyset_s.ru index 907eb49af..b7f161c9e 100644 --- a/gem/apps/keyset_s.ru +++ b/gem/apps/keyset_s.ru @@ -16,7 +16,7 @@ # URL # http://0.0.0.0:8000 -VERSION = '9.2.2' +VERSION = '9.3.0' # Bundle require 'bundler/inline' diff --git a/gem/apps/rails.ru b/gem/apps/rails.ru index 6102c21a1..7ebbcce7e 100644 --- a/gem/apps/rails.ru +++ b/gem/apps/rails.ru @@ -16,7 +16,7 @@ # URL # http://0.0.0.0:8000 -VERSION = '9.2.2' +VERSION = '9.3.0' # Gemfile require 'bundler/inline' diff --git a/gem/apps/repro.ru b/gem/apps/repro.ru index dd2419795..bdf341d24 100644 --- a/gem/apps/repro.ru +++ b/gem/apps/repro.ru @@ -16,7 +16,7 @@ # URL # http://0.0.0.0:8000 -VERSION = '9.2.2' +VERSION = '9.3.0' # Bundle require 'bundler/inline' diff --git a/gem/bin/pagy b/gem/bin/pagy index 1ff20b592..93a918a15 100755 --- a/gem/bin/pagy +++ b/gem/bin/pagy @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -VERSION = '9.2.2' +VERSION = '9.3.0' LINUX = RbConfig::CONFIG['host_os'].include?('linux') HOST = '0.0.0.0' PORT = '8000' diff --git a/gem/config/pagy.rb b/gem/config/pagy.rb index bc2019dff..22e4c2c25 100644 --- a/gem/config/pagy.rb +++ b/gem/config/pagy.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Pagy initializer file (9.2.2) +# Pagy initializer file (9.3.0) # Customize only what you really need and notice that the core Pagy works also without any of the following lines. # Should you just cherry pick part of this file, please maintain the require-order of the extras diff --git a/gem/javascripts/pagy.min.js b/gem/javascripts/pagy.min.js index b581ab442..b393dce7d 100644 --- a/gem/javascripts/pagy.min.js +++ b/gem/javascripts/pagy.min.js @@ -1,4 +1,4 @@ -window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>QQ.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_limit__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(TH){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"9.2.2",init(B){const E=(B instanceof Element?B:document).querySelectorAll("[data-pagy]");for(let z of E)try{const G=Uint8Array.from(atob(z.getAttribute("data-pagy")),(L)=>L.charCodeAt(0)),[F,...K]=JSON.parse(new TextDecoder().decode(G));if(F==="nav")x(z,K);else if(F==="combo")A(z,K);else if(F==="selector")C(z,K);else console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'",z,F)}catch(G){console.warn("Skipped Pagy.init() for: %o\n%s",z,G)}}}})(); +window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>QQ.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_limit__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(TH){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"9.3.0",init(B){const E=(B instanceof Element?B:document).querySelectorAll("[data-pagy]");for(let z of E)try{const G=Uint8Array.from(atob(z.getAttribute("data-pagy")),(L)=>L.charCodeAt(0)),[F,...K]=JSON.parse(new TextDecoder().decode(G));if(F==="nav")x(z,K);else if(F==="combo")A(z,K);else if(F==="selector")C(z,K);else console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'",z,F)}catch(G){console.warn("Skipped Pagy.init() for: %o\n%s",z,G)}}}})(); -//# debugId=95660885F5F5D95D64756E2164756E21 +//# debugId=B39A28D1D50FFD7564756E2164756E21 //# sourceMappingURL=pagy.min.js.map diff --git a/gem/javascripts/pagy.min.js.map b/gem/javascripts/pagy.min.js.map index 26050d1a9..af08324ae 100644 --- a/gem/javascripts/pagy.min.js.map +++ b/gem/javascripts/pagy.min.js.map @@ -2,9 +2,9 @@ "version": 3, "sources": ["../../src/pagy.ts"], "sourcesContent": [ - "type NavArgs = readonly [Tokens, Sequels, null | LabelSequels, string?]\ntype ComboArgs = readonly [string, string?]\ntype SelectorArgs = readonly [number, string, string?]\ntype JsonArgs = ['nav', NavArgs] | ['combo', ComboArgs] | ['selector', SelectorArgs]\n\ninterface Tokens {\n readonly before:string\n readonly a:string\n readonly current:string\n readonly gap:string\n readonly after:string\n}\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => e.target.querySelectorAll(\".pagy-rjs\")\n .forEach(el => el.pagyRender())));\n // Init the *_nav_js helpers\n const initNav = (el:NavElement, [tokens, sequels, labelSequels, trimParam]:NavArgs) => {\n const container = el.parentElement ?? el;\n const widths = Object.keys(sequels).map(w => parseInt(w)).sort((a, b) => b - a);\n let lastWidth = -1;\n const fillIn = (a:string, page:string, label:string):string =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = function () {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n let html = tokens.before; // already trimmed in html\n const series = sequels[width.toString()];\n const labels = labelSequels?.[width.toString()] ?? series.map(l => l.toString());\n series.forEach((item, i) => {\n const label = labels[i];\n let filled;\n if (typeof item === \"number\") {\n filled = fillIn(tokens.a, item.toString(), label);\n } else if (item === \"gap\") {\n filled = tokens.gap;\n } else { // active page\n filled = fillIn(tokens.current, item, label);\n }\n html += (typeof trimParam === \"string\" && item == 1) ? trim(filled, trimParam) : filled;\n });\n html += tokens.after;\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initCombo = (el:Element, [url_token, trimParam]:ComboArgs) =>\n initInput(el, inputValue => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);\n\n // Init the limit_selector_js helper\n const initSelector = (el:Element, [from, url_token, trimParam]:SelectorArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue);\n return [page, url];\n }, trimParam);\n };\n\n // Init the input element\n const initInput = (el:Element, getVars:(v:string) => [string, string], trimParam?:string) => {\n const input = el.querySelector(\"input\") as HTMLInputElement;\n const link = el.querySelector(\"a\") as HTMLAnchorElement;\n const initial = input.value;\n const action = function () {\n if (input.value === initial) { return } // not changed\n const [min, val, max] = [input.min, input.value, input.max].map(n => parseInt(n) || 0);\n if (val < min || val > max) { // reset invalid/out-of-range\n input.value = initial;\n input.select();\n return;\n }\n let [page, url] = getVars(input.value); // eslint-disable-line prefer-const\n if (typeof trimParam === \"string\" && page === \"1\") { url = trim(url, trimParam) }\n link.href = url;\n link.click();\n };\n [\"change\", \"focus\"].forEach(e => input.addEventListener(e, () => input.select())); // auto-select\n input.addEventListener(\"focusout\", action); // trigger action\n input.addEventListener(\"keypress\", e => { if (e.key === \"Enter\") { action() } }); // trigger action\n };\n\n // Trim the ${page-param}=1 params in links\n const trim = (a:string, param:string) =>\n a.replace(new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`), \"\");\n\n // Public interface\n return {\n version: \"9.2.2\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document;\n const elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const uint8array = Uint8Array.from(atob(el.getAttribute(\"data-pagy\") as string), c => c.charCodeAt(0));\n const [keyword, ...args] = JSON.parse((new TextDecoder()).decode(uint8array)) as JsonArgs; // base64-utf8 -> JSON -> Array\n if (keyword === \"nav\") {\n initNav(el as NavElement, args as unknown as NavArgs);\n } else if (keyword === \"combo\") {\n initCombo(el, args as unknown as ComboArgs);\n } else if (keyword === \"selector\") {\n initSelector(el, args as unknown as SelectorArgs);\n } else {\n console.warn(\"Skipped Pagy.init() for: %o\\nUnknown keyword '%s'\", el, keyword);\n }\n } catch (err) { console.warn(\"Skipped Pagy.init() for: %o\\n%s\", el, err) }\n }\n }\n };\n})();\n\nexport default Pagy;\n" + "type NavArgs = readonly [Tokens, Sequels, null | LabelSequels, string?]\ntype ComboArgs = readonly [string, string?]\ntype SelectorArgs = readonly [number, string, string?]\ntype JsonArgs = ['nav', NavArgs] | ['combo', ComboArgs] | ['selector', SelectorArgs]\n\ninterface Tokens {\n readonly before:string\n readonly a:string\n readonly current:string\n readonly gap:string\n readonly after:string\n}\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => e.target.querySelectorAll(\".pagy-rjs\")\n .forEach(el => el.pagyRender())));\n // Init the *_nav_js helpers\n const initNav = (el:NavElement, [tokens, sequels, labelSequels, trimParam]:NavArgs) => {\n const container = el.parentElement ?? el;\n const widths = Object.keys(sequels).map(w => parseInt(w)).sort((a, b) => b - a);\n let lastWidth = -1;\n const fillIn = (a:string, page:string, label:string):string =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = function () {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n let html = tokens.before; // already trimmed in html\n const series = sequels[width.toString()];\n const labels = labelSequels?.[width.toString()] ?? series.map(l => l.toString());\n series.forEach((item, i) => {\n const label = labels[i];\n let filled;\n if (typeof item === \"number\") {\n filled = fillIn(tokens.a, item.toString(), label);\n } else if (item === \"gap\") {\n filled = tokens.gap;\n } else { // active page\n filled = fillIn(tokens.current, item, label);\n }\n html += (typeof trimParam === \"string\" && item == 1) ? trim(filled, trimParam) : filled;\n });\n html += tokens.after;\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initCombo = (el:Element, [url_token, trimParam]:ComboArgs) =>\n initInput(el, inputValue => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);\n\n // Init the limit_selector_js helper\n const initSelector = (el:Element, [from, url_token, trimParam]:SelectorArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue);\n return [page, url];\n }, trimParam);\n };\n\n // Init the input element\n const initInput = (el:Element, getVars:(v:string) => [string, string], trimParam?:string) => {\n const input = el.querySelector(\"input\") as HTMLInputElement;\n const link = el.querySelector(\"a\") as HTMLAnchorElement;\n const initial = input.value;\n const action = function () {\n if (input.value === initial) { return } // not changed\n const [min, val, max] = [input.min, input.value, input.max].map(n => parseInt(n) || 0);\n if (val < min || val > max) { // reset invalid/out-of-range\n input.value = initial;\n input.select();\n return;\n }\n let [page, url] = getVars(input.value); // eslint-disable-line prefer-const\n if (typeof trimParam === \"string\" && page === \"1\") { url = trim(url, trimParam) }\n link.href = url;\n link.click();\n };\n [\"change\", \"focus\"].forEach(e => input.addEventListener(e, () => input.select())); // auto-select\n input.addEventListener(\"focusout\", action); // trigger action\n input.addEventListener(\"keypress\", e => { if (e.key === \"Enter\") { action() } }); // trigger action\n };\n\n // Trim the ${page-param}=1 params in links\n const trim = (a:string, param:string) =>\n a.replace(new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`), \"\");\n\n // Public interface\n return {\n version: \"9.3.0\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document;\n const elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const uint8array = Uint8Array.from(atob(el.getAttribute(\"data-pagy\") as string), c => c.charCodeAt(0));\n const [keyword, ...args] = JSON.parse((new TextDecoder()).decode(uint8array)) as JsonArgs; // base64-utf8 -> JSON -> Array\n if (keyword === \"nav\") {\n initNav(el as NavElement, args as unknown as NavArgs);\n } else if (keyword === \"combo\") {\n initCombo(el, args as unknown as ComboArgs);\n } else if (keyword === \"selector\") {\n initSelector(el, args as unknown as SelectorArgs);\n } else {\n console.warn(\"Skipped Pagy.init() for: %o\\nUnknown keyword '%s'\", el, keyword);\n }\n } catch (err) { console.warn(\"Skipped Pagy.init() for: %o\\n%s\", el, err) }\n }\n }\n };\n})();\n\nexport default Pagy;\n" ], "mappings": "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", - "debugId": "95660885F5F5D95D64756E2164756E21", + "debugId": "B39A28D1D50FFD7564756E2164756E21", "names": [] } \ No newline at end of file diff --git a/gem/javascripts/pagy.mjs b/gem/javascripts/pagy.mjs index b6a99281a..17bcb1b60 100644 --- a/gem/javascripts/pagy.mjs +++ b/gem/javascripts/pagy.mjs @@ -73,7 +73,7 @@ const Pagy = (() => { }; const trim = (a, param) => a.replace(new RegExp(`[?&]${param}=1\\b(?!&)|\\b${param}=1&`), ""); return { - version: "9.2.2", + version: "9.3.0", init(arg) { const target = arg instanceof Element ? arg : document; const elements = target.querySelectorAll("[data-pagy]"); diff --git a/gem/lib/pagy.rb b/gem/lib/pagy.rb index bdcf6f59a..d03dd1e18 100644 --- a/gem/lib/pagy.rb +++ b/gem/lib/pagy.rb @@ -6,7 +6,7 @@ # Top superclass: it should define only what's common to all the subclasses class Pagy - VERSION = '9.2.2' + VERSION = '9.3.0' # Core default: constant for easy access, but mutable for customizable defaults DEFAULT = { count_args: [:all], # rubocop:disable Style/MutableConstant diff --git a/gem/lib/pagy/keyset.rb b/gem/lib/pagy/keyset.rb index c61b15a34..74f440219 100644 --- a/gem/lib/pagy/keyset.rb +++ b/gem/lib/pagy/keyset.rb @@ -43,7 +43,7 @@ def initialize(set, **vars) return unless @page latest = JSON.parse(B64.urlsafe_decode(@page)).transform_keys(&:to_sym) - @latest = @vars[:typecast_latest]&.(latest) || typecast_latest(latest) + @latest = typecast_latest(latest) raise InternalError, 'page and keyset are not consistent' \ unless @latest.keys == @keyset.keys end @@ -53,24 +53,28 @@ def next records return unless @more - @next ||= B64.urlsafe_encode(latest_from(@records.last).to_json) + @next ||= begin + hash = keyset_attributes_from(@records.last) + json = @vars[:jsonify_keyset_attributes]&.(hash) || hash.to_json + B64.urlsafe_encode(json) + end end # Fetch the array of records for the current page def records @records ||= begin - @set = apply_select if select? - if @latest - # :nocov: - @set = @vars[:after_latest]&.(@set, @latest) || # deprecated - # :nocov: - @vars[:filter_newest]&.(@set, @latest, @keyset) || - filter_newest - end - records = @set.limit(@limit + 1).to_a - @more = records.size > @limit && !records.pop.nil? - records - end + @set = apply_select if select? + if @latest + # :nocov: + @set = @vars[:after_latest]&.(@set, @latest) || # deprecated + # :nocov: + @vars[:filter_newest]&.(@set, @latest, @keyset) || + filter_newest + end + records = @set.limit(@limit + 1).to_a + @more = records.size > @limit && !records.pop.nil? + records + end end protected diff --git a/gem/lib/pagy/keyset/active_record.rb b/gem/lib/pagy/keyset/active_record.rb index ad4a49195..0d0155b57 100644 --- a/gem/lib/pagy/keyset/active_record.rb +++ b/gem/lib/pagy/keyset/active_record.rb @@ -7,8 +7,8 @@ class Keyset class ActiveRecord < Keyset protected - # Get the keyset attributes of the record - def latest_from(latest_record) = latest_record.slice(*@keyset.keys) + # Get the keyset attributes from the record + def keyset_attributes_from(record) = record.slice(*@keyset.keys) # Extract the keyset from the set def extract_keyset diff --git a/gem/lib/pagy/keyset/sequel.rb b/gem/lib/pagy/keyset/sequel.rb index e828d9dad..58deefd68 100644 --- a/gem/lib/pagy/keyset/sequel.rb +++ b/gem/lib/pagy/keyset/sequel.rb @@ -7,8 +7,8 @@ class Keyset class Sequel < Keyset protected - # Get the keyset attributes of the latest record - def latest_from(latest_record) = latest_record.to_hash.slice(*@keyset.keys) + # Get the keyset attributes from the record + def keyset_attributes_from(record) = record.to_hash.slice(*@keyset.keys) # Extract the keyset from the set def extract_keyset diff --git a/gem/pagy.gemspec b/gem/pagy.gemspec index d7b264250..9c3ebdf72 100644 --- a/gem/pagy.gemspec +++ b/gem/pagy.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = 'pagy' - s.version = '9.2.2' + s.version = '9.3.0' s.authors = ['Domizio Demichelis'] s.email = ['dd.nexus@gmail.com'] s.summary = 'The best pagination ruby gem' diff --git a/package.json b/package.json index 5b5cd6628..b278ed639 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,13 @@ "eslint-plugin-promise": "7.1.0", "html-validate": "8.25.0", "start-server-and-test": "2.0.8", - "@eslint/js": "9.14.0", + "@eslint/js": "9.15.0", "@types/eslint__js": "^8.42.3", - "eslint": "9.14.0", + "eslint": "9.15.0", "eslint-plugin-align-assignments": "^1.1.2", "retypeapp-linux-x64": "3.6.0", "typescript": "5.6.3", - "typescript-eslint": "8.13.0" + "typescript-eslint": "8.14.0" }, "workspaces": ["e2e"] } diff --git a/quick-start.md b/quick-start.md index cf5ed75d1..c5d68335f 100644 --- a/quick-start.md +++ b/quick-start.md @@ -40,7 +40,7 @@ If you use Bundler, add the gem in the Gemfile, optionally avoiding the next maj see [RubyGem Specifiers](http://guides.rubygems.org/patterns/#pessimistic-version-constraint)): ```ruby Gemfile -gem 'pagy', '~> 9.2' # omit patch digit +gem 'pagy', '~> 9.3' # omit patch digit ``` +++ Without Bundler diff --git a/retype.yml b/retype.yml index cc32a935a..2219ca164 100644 --- a/retype.yml +++ b/retype.yml @@ -8,7 +8,7 @@ url: https://ddnexus.github.io/pagy branding: title: Pagy - label: 9.2.2 + label: 9.3.0 colors: label: text: "#FFFFFF" diff --git a/src/pagy.ts b/src/pagy.ts index e1175c741..1487e6633 100644 --- a/src/pagy.ts +++ b/src/pagy.ts @@ -94,7 +94,7 @@ const Pagy = (() => { // Public interface return { - version: "9.2.2", + version: "9.3.0", // Scan for elements with a "data-pagy" attribute and call their init functions with the decoded args init(arg?:Element) { diff --git a/test/pagy/keyset_test.rb b/test/pagy/keyset_test.rb index e9fa1b86c..78eb5925d 100644 --- a/test/pagy/keyset_test.rb +++ b/test/pagy/keyset_test.rb @@ -41,12 +41,12 @@ _(records.size).must_equal 10 _(records.first.id).must_equal 13 end - it 'uses :typecast_latest' do + it 'uses :jsonify_keyset_attributes' do pagy = Pagy::Keyset.new(model.order(:id), page: "eyJpZCI6MTB9", limit: 10, - typecast_latest: ->(latest) { latest }) - _ = pagy.records + jsonify_keyset_attributes: lambda(&:to_json)) + _(pagy.next).must_equal("eyJpZCI6MjB9") _(pagy.latest).must_equal({id: 10}) end it 'uses :filter_newest' do