Module: Pagy::CountishPaginator
- Defined in:
- lib/pagy/toolbox/paginators/countish.rb
Class Method Summary collapse
-
.paginate(collection, options) ⇒ Object
Return the Offset::Countish instance and records.
-
.setup_options(count, epoch, collection, options) ⇒ Object
Get the count from the page and set epoch when ttl (Time To Live) requires it.
Class Method Details
.paginate(collection, options) ⇒ Object
Return the Offset::Countish instance and records
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pagy/toolbox/paginators/countish.rb', line 10 def paginate(collection, ) [:page] ||= [:request].resolve_page(force_integer: false) if [:page].is_a?(String) page, count, epoch = [:page].split.map(&:to_i) [:page] = page end [:limit] = [:request].resolve_limit (count, epoch, collection, ) pagy = Offset::Countish.new(**) [pagy, pagy.records(collection)] end |
.setup_options(count, epoch, collection, options) ⇒ Object
Get the count from the page and set epoch when ttl (Time To Live) requires it
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pagy/toolbox/paginators/countish.rb', line 26 def (count, epoch, collection, ) now = Time.now.to_i ongoing = ![:ttl] || (epoch && epoch <= now && now < (epoch + [:ttl])) if ![:count] && count && ongoing [:count] = count [:epoch] = epoch if [:ttl] else # recount [:count] ||= Countable.get_count(collection, ) [:epoch] = now if [:ttl] end end |