Class: Pagy::Countless

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

Overview

No need to know the count to paginate

Constant Summary

Constants inherited from Pagy

DEFAULT, ElasticsearchRails, LABEL_TOKEN, Meilisearch, PAGE_TOKEN, Searchkick, VERSION

Instance Attribute Summary

Attributes inherited from Pagy

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

Instance Method Summary collapse

Methods inherited from Pagy

#label, #label_for, root

Methods included from SearchkickExtra::PagyExtension

#new_from_searchkick

Methods included from MeilisearchExtra::PagyExtension

#new_from_meilisearch

Methods included from ElasticsearchRailsExtra::PagyAddOn

#new_from_elasticsearch_rails

Methods included from GearboxExtra

#setup_items_var, #setup_last_var, #setup_offset_var

Methods included from JSTools::PagyAddOn

#label_sequels, #sequels

Methods included from OverflowExtra::PagyOverride

#overflow?

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
# 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_offset_var
end

Instance Method Details

#finalize(fetched_size) ⇒ Object

Finalize the instance variables based on the fetched size

Raises:



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

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

  @last = fetched_size > @items ? @page + 1 : @page
  @last = vars[:max_pages] if vars[:max_pages] && @last > vars[:max_pages]
  raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last

  @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



35
36
37
# File 'lib/pagy/countless.rb', line 35

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