module Pagy::CountlessExtra
def pagy_countless(collection, vars = {})
def pagy_countless(collection, vars = {}) pagy = Pagy::Countless.new(pagy_countless_get_vars(collection, vars)) [pagy, pagy_countless_get_items(collection, pagy)] end
def pagy_countless_get_items(collection, pagy)
def pagy_countless_get_items(collection, pagy) # This should work with ActiveRecord, Sequel, Mongoid... return collection.offset(pagy.offset).limit(pagy.items) if pagy.vars[:countless_minimal] items = collection.offset(pagy.offset).limit(pagy.items + 1).to_a items_size = items.size items.pop if items_size == pagy.items + 1 # finalize may adjust pagy.items, so must be used after checking the size pagy.finalize(items_size) items end
def pagy_countless_get_vars(_collection, vars)
def pagy_countless_get_vars(_collection, vars) pagy_set_items_from_params(vars) if defined?(ItemsExtra) vars[:page] ||= params[vars[:page_param] || DEFAULT[:page_param]] vars end