lib/pagy/countless.rb in pagy-1.2.1 vs lib/pagy/countless.rb in pagy-1.3

- old
+ new

@@ -12,19 +12,18 @@ or raise(ArgumentError, "expected :#{k} >= #{min}; got #{@vars[k].inspect}") end @offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset) end - # Finalize the instance variables based on the retrieved items - def finalize(items) - items == 0 && @page > 1 and raise(OverflowError.new(self), "page #{@page} got no items") - @pages = @last = (items > @items ? @page + 1 : @page) # set the @pages and @last - @items = items if items < @items && items > 0 # adjust items for last non-empty page - @from = items == 0 ? 0 : @offset+1 - @outset # page begins from item - @to = items == 0 ? 0 : @offset + @items - @outset # page ends to item - @prev = (@page-1 unless @page == 1) # nil if no prev page - @next = (@page+1 unless @page == @last) # nil if no next page - @next = (@page == @last ? (1 if @vars[:cycle]) : @page+1) # nil if no next page + # Finalize the instance variables based on the fetched items + def finalize(fetched) + fetched == 0 && @page > 1 and raise(OverflowError.new(self), "page #{@page} got no items") + @pages = @last = (fetched > @items ? @page + 1 : @page) # set the @pages and @last + @items = fetched if fetched < @items && fetched > 0 # adjust items for last non-empty page + @from = fetched == 0 ? 0 : @offset+1 - @outset # page begins from item + @to = fetched == 0 ? 0 : @offset + @items - @outset # page ends to item + @prev = (@page-1 unless @page == 1) # nil if no prev page + @next = @page == @last ? (1 if @vars[:cycle]) : @page+1 # nil if no next page, 1 if :cycle self end end end