Class: Pagy::Offset::Countless

Inherits:
Pagy::Offset show all
Defined in:
lib/pagy/classes/offset/countless.rb

Overview

Offset pagination without a count

Constant Summary

Constants inherited from Pagy::Offset

DEFAULT

Constants inherited from Pagy

A_TAG, DEFAULT, DEFAULT_DATA_KEYS, DEFAULT_HEADERS_MAP, LABEL_TOKEN, LIMIT_TOKEN, Method, Pagy::OPTIONS, PAGE_TOKEN, ROOT, SERIES_SLOTS, VERSION

Instance Attribute Summary

Attributes inherited from Pagy::Offset

#count, #from, #in, #last, #offset, #previous, #to

Attributes inherited from Pagy

#in, #limit, #next, #options, #page

Instance Method Summary collapse

Methods included from Rangeable

#in_range?

Methods inherited from Pagy

#data_hash, #headers_hash, #info_tag, #input_nav_js, #limit_tag_js, #next_tag, options, #page_url, #previous_tag, #series_nav, #series_nav_js, #urls_hash

Methods included from Configurable

#dev_tools, #sync_javascript, #translate_with_the_slower_i18n_gem!

Constructor Details

#initializeCountless

Returns a new instance of Countless.



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

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

Instance Method Details

#records(collection) ⇒ Object



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

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