Class: Pagy::Countless
- 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
-
#finalize(fetched_size) ⇒ Object
Finalize the instance variables based on the fetched size.
-
#initialize(vars = {}) ⇒ Countless
constructor
Merge and validate the options, do some simple arithmetic and set a few instance variables.
-
#series ⇒ Object
Override the original series.
Methods inherited from Pagy
Methods included from SearchkickExtra::Pagy
Methods included from MeilisearchExtra::Pagy
Methods included from ElasticsearchRailsExtra::Pagy
Methods included from GearboxExtra
#setup_items_var, #setup_offset_var, #setup_pages_var
Methods included from OverflowExtra::Pagy
Methods included from FrontendHelpers::Pagy
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_offset_var setup_params_var end |
Instance Method Details
#finalize(fetched_size) ⇒ Object
Finalize the instance variables based on the fetched size
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 |
#series ⇒ Object
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 |