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
Class methods
Как 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
Ruby-совместимый алиас Array#length (в Crystal — size)
Магическая обёртка над Array#replace: если переданный массив короче лимита per_page, мы знаем, что находимся на последней странице, и total_entries вычисляется сам (offset + length).