Class: Uchi::Pagy::Offset
- Inherits:
-
Uchi::Pagy
- Object
- Uchi::Pagy
- Uchi::Pagy::Offset
- Defined in:
- lib/uchi/pagy/classes/offset/offset.rb
Overview
Implements Offset Pagination
Constant Summary collapse
- DEFAULT =
{ page: 1 }.freeze
Constants inherited from Uchi::Pagy
A_TAG, LABEL_TOKEN, LIMIT_TOKEN, Method, PAGE_TOKEN, ROOT, VERSION
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#in ⇒ Object
readonly
Returns the value of attribute in.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Attributes inherited from Uchi::Pagy
#limit, #next, #options, #page
Instance Method Summary collapse
-
#initialize ⇒ Offset
constructor
rubocop:disable Lint/MissingSuper.
- #records(collection) ⇒ Object
Methods included from Rangeable
Methods inherited from Uchi::Pagy
Methods included from Configurable
#dev_tools, #sync_javascript, #translate_with_the_slower_i18n_gem!
Constructor Details
#initialize ⇒ Offset
rubocop:disable Lint/MissingSuper
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 17 def initialize(**) # rubocop:disable Lint/MissingSuper (**) assign_and_check(limit: 1, count: 0, page: 1) assign_last assign_offset return unless in_range? { @page <= @last } @from = [@offset + 1, @count].min @to = [@offset + @limit, @count].min @in = [@to - @from + 1, @count].min assign_previous_and_next end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
30 31 32 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 30 def count @count end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
30 31 32 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 30 def from @from end |
#in ⇒ Object (readonly)
Returns the value of attribute in.
30 31 32 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 30 def in @in end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
30 31 32 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 30 def last @last end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
30 31 32 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 30 def offset @offset end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
30 31 32 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 30 def previous @previous end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
30 31 32 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 30 def to @to end |
Instance Method Details
#records(collection) ⇒ Object
32 33 34 |
# File 'lib/uchi/pagy/classes/offset/offset.rb', line 32 def records(collection) collection.offset(@offset).limit(@limit) end |