Class: Pagy::Offset::Countless

Inherits:
Offset
  • Object
show all
Includes:
Deprecated::Countless
Defined in:
lib/pagy/classes/offset/countless.rb

Overview

Offset pagination without any COUNT query

Instance Method Summary collapse

Methods included from Deprecated::Countless

#upto_max_pages

Constructor Details

#initializeCountless

Returns a new instance of Countless.



7
8
9
10
11
12
# File 'lib/pagy/classes/offset/countless.rb', line 7

def initialize(**)
  assign_options(**)
  assign_and_check(limit: 1, page: 1)
  @last = @options[:last] unless @options[:headless]
  assign_offset
end

Instance Method Details

#records(collection) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/pagy/classes/offset/countless.rb', line 14

def records(collection)
  return super if @options[:headless]

  fetched = collection.offset(@offset).limit(@limit + 1).to_a # eager load limit + 1
  finalize(fetched.size)                                      # finalize the pagy object
  fetched[0, @limit]                                          # ignore the extra item
end