lib/pagy/countless.rb in pagy-5.0.1 vs lib/pagy/countless.rb in pagy-5.1.0

- old
+ new

@@ -12,22 +12,24 @@ setup_vars(page: 1, outset: 0) setup_items_var @offset = (@items * (@page - 1)) + @outset end - # Finalize the instance variables based on the fetched items - def finalize(fetched) - raise OverflowError.new(self, :page, "to be < #{@page}") if fetched.zero? && @page > 1 + # Finalize the instance variables based on the fetched size + def finalize(fetched_size) + raise OverflowError.new(self, :page, "to be < #{@page}") if fetched_size.zero? && @page > 1 - @pages = @last = (fetched > @items ? @page + 1 : @page) - @in = [fetched, @items].min + @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 + # Override the original series. + # Return nil if :countless_minimal is enabled def series(_size = @vars[:size]) super unless @vars[:countless_minimal] end end end