module Pagy::CountlessExtra
def pagy_countless(collection, vars = {})
def pagy_countless(collection, vars = {}) pagy = Countless.new(pagy_countless_get_vars(collection, vars)) [pagy, pagy_countless_get_items(collection, pagy)] end
def pagy_countless_get_items(collection, pagy)
Sub-method called only by #pagy_countless: here for easy customization of record-extraction by overriding
def pagy_countless_get_items(collection, pagy) return collection.offset(pagy.offset).limit(pagy.items) if pagy.vars[:countless_minimal] fetched = collection.offset(pagy.offset).limit(pagy.items + 1).to_a # eager load items + 1 pagy.finalize(fetched.size) # finalize the pagy object fetched[0, pagy.items] # ignore eventual extra item 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