class

WillPaginate::Collection(T)

Inherits WillPaginate::CollectionMethods < Array < Comparable < Indexable::Mutable < Indexable < Enumerable < Iterable < Reference < Object

= Ключ к пагинации

WillPaginate::Collection — обычный массив с дополнительными свойствами (current_page, per_page, total_entries), используемыми вью-хелперами. См. также create.

Constructors

new(page : PageNumber | Int32 | Int64 | String | Nil, per_page : Int32 | Nil = nil, total : Int32 | Nil = nil)

Class methods

create(page : PageNumber | Int32 | Int64 | String | Nil, per_page : Int32 | Nil = nil, total : Int32 | Nil = nil, &block : self -> _)

Как new, но передаёт объект в блок и возвращает его после — удобно для ручной пагинации:

entries = WillPaginate::Collection(Int32).create(1, 10) do |pager| result = fetch(limit: pager.per_page, offset: pager.offset) pager.replace(result) pager.total_entries = count_all unless pager.total_entries end

Instance methods

current_page
length

Ruby-совместимый алиас Array#length (в Crystal — size)

per_page
replace(other : Array(T)) : self

Магическая обёртка над Array#replace: если переданный массив короче лимита per_page, мы знаем, что находимся на последней странице, и total_entries вычисляется сам (offset + length).

total_entries
total_entries=(number : Int32)