Class: Pagy::Keyset::Keynav
- Inherits:
-
Pagy::Keyset
- Object
- Pagy
- Pagy::Keyset
- Pagy::Keyset::Keynav
- Includes:
- Deprecated::Keynav, NumericHelpers
- Defined in:
- lib/pagy/classes/keyset/keynav.rb
Overview
Keyset pagination with broad UI support
Direct Known Subclasses
Defined Under Namespace
Classes: ActiveRecord, Sequel
Constant Summary collapse
- PRIOR_PREFIX =
Avoid conflicts between filter arguments in composite SQL fragments
'prior_'- PAGE_PREFIX =
'page_'
Constants inherited from Pagy
A_TAG, DEFAULT, DEFAULT_DATA_KEYS, DEFAULT_HEADERS_MAP, LABEL_TOKEN, LIMIT_TOKEN, Method, OPTIONS, PAGE_TOKEN, ROOT, SERIES_SLOTS, VERSION
Instance Attribute Summary collapse
-
#last ⇒ Object
(also: #pages)
readonly
Returns the value of attribute last.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
-
#update ⇒ Object
readonly
Returns the value of attribute update.
Attributes inherited from Pagy
Instance Method Summary collapse
-
#initialize(set) ⇒ Keynav
constructor
Finalize the instance variables needed for the UI.
-
#next ⇒ Object
Prepare the @update for the client when it’s a new page, and return the next page number.
Methods included from NumericHelpers
#info_tag, #input_nav_js, #limit_tag_js, #previous_tag, #series_nav, #series_nav_js
Methods inherited from Pagy::Keyset
Methods inherited from Pagy
#data_hash, #headers_hash, #next_tag, #page_url, #urls_hash
Methods included from Configurable
#dev_tools, #options, #sync, #sync_javascript, #translate_with_the_slower_i18n_gem!
Methods included from Discontinued
Methods included from Deprecated::Pagy
Constructor Details
#initialize(set) ⇒ Keynav
Finalize the instance variables needed for the UI
18 19 20 21 22 23 |
# File 'lib/pagy/classes/keyset/keynav.rb', line 18 def initialize(set, **) super @previous = @page - 1 unless @page == 1 @in = @records.size end |
Instance Attribute Details
#last ⇒ Object (readonly) Also known as: pages
Returns the value of attribute last.
25 26 27 |
# File 'lib/pagy/classes/keyset/keynav.rb', line 25 def last @last end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
25 26 27 |
# File 'lib/pagy/classes/keyset/keynav.rb', line 25 def previous @previous end |
#update ⇒ Object (readonly)
Returns the value of attribute update.
25 26 27 |
# File 'lib/pagy/classes/keyset/keynav.rb', line 25 def update @update end |
Instance Method Details
#next ⇒ Object
Prepare the @update for the client when it’s a new page, and return the next page number
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pagy/classes/keyset/keynav.rb', line 29 def next records @count = 0 if !@more && @page == 1 # empty records (trigger the right info message for known 0 count) return unless @more @next ||= begin unless @page_cutoff @page_cutoff = extract_cutoff @last += 1 # reflect the added cutoff @update.push(@last, [@page, 1, @page_cutoff]) # last + splice arguments for the client cutoffs end @page + 1 end end |