Class: Pagy::Countless

Inherits:
Pagy
  • Object
show all
Includes:
OverflowExtra::Countless
Defined in:
lib/pagy/countless.rb

Overview

No need to know the count to paginate

Constant Summary

Constants inherited from Pagy

DEFAULT, ElasticsearchRails, LABEL_PLACEHOLDER, Meilisearch, PAGE_PLACEHOLDER, Searchkick, VERSION

Instance Attribute Summary

Attributes inherited from Pagy

#count, #from, #in, #items, #last, #next, #offset, #page, #pages, #params, #prev, #to, #vars

Instance Method Summary collapse

Methods inherited from Pagy

#label, #label_for, root

Methods included from SearchkickExtra::Pagy

#new_from_searchkick

Methods included from MeilisearchExtra::Pagy

#new_from_meilisearch

Methods included from ElasticsearchRailsExtra::Pagy

#new_from_elasticsearch_rails

Methods included from GearboxExtra

#setup_items_var, #setup_pages_var

Methods included from OverflowExtra::Pagy

#overflow?

Methods included from FrontendHelpers::Pagy

#label_sequels, #sequels

Constructor Details

#initialize(vars = {}) ⇒ Countless

Merge and validate the options, do some simple arithmetic and set a few instance variables



10
11
12
13
14
15
16
# File 'lib/pagy/countless.rb', line 10

def initialize(vars = {}) # rubocop:disable Lint/MissingSuper
  normalize_vars(vars)
  setup_vars(page: 1, outset: 0)
  setup_items_var
  setup_params_var
  @offset = (@items * (@page - 1)) + @outset
end

Instance Method Details

#finalize(fetched_size) ⇒ Object

Finalize the instance variables based on the fetched size

Raises:



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pagy/countless.rb', line 19

def finalize(fetched_size)
  raise OverflowError.new(self, :page, "to be < #{@page}", @page) if fetched_size.zero? && @page > 1

  @pages = @last = (fetched_size > @items ? @page + 1 : @page)
  @in    = [fetched_size, @items].min
  @from  = @in.zero? ? 0 : @offset - @outset + 1
  @to    = @offset - @outset + @in
  @prev  = (@page - 1 unless @page == 1)
  @next  = @page == @last ? (1 if @vars[:cycle]) : @page + 1
  self
end

#seriesObject

Override the original series. Return nil if :countless_minimal is enabled



33
34
35
# File 'lib/pagy/countless.rb', line 33

def series(*)
  super unless @vars[:countless_minimal]
end