Class: Pagy::Offset

Inherits:
Pagy
  • Object
show all
Includes:
Rangeable, Shiftable
Defined in:
lib/pagy/classes/offset/offset.rb,
lib/pagy/classes/offset/countish.rb,
lib/pagy/classes/offset/countless.rb

Overview

Implements Offset Pagination

Direct Known Subclasses

Countish, Countless, SearchBase

Defined Under Namespace

Classes: Countish, Countless

Constant Summary collapse

DEFAULT =
{ page: 1 }.freeze

Constants inherited from Pagy

A_TAG, DEFAULT_DATA_KEYS, DEFAULT_HEADERS_MAP, LABEL_TOKEN, LIMIT_TOKEN, Method, PAGE_TOKEN, ROOT, SERIES_SLOTS, VERSION

Instance Attribute Summary collapse

Attributes inherited from Pagy

#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

#initializeOffset

Returns a new instance of Offset.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pagy/classes/offset/offset.rb', line 17

def initialize(**)
  assign_options(**)
  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

#countObject (readonly)

Returns the value of attribute count.



30
31
32
# File 'lib/pagy/classes/offset/offset.rb', line 30

def count
  @count
end

#fromObject (readonly)

Returns the value of attribute from.



30
31
32
# File 'lib/pagy/classes/offset/offset.rb', line 30

def from
  @from
end

#inObject (readonly)

Returns the value of attribute in.



30
31
32
# File 'lib/pagy/classes/offset/offset.rb', line 30

def in
  @in
end

#lastObject (readonly) Also known as: pages

Returns the value of attribute last.



30
31
32
# File 'lib/pagy/classes/offset/offset.rb', line 30

def last
  @last
end

#offsetObject (readonly)

Returns the value of attribute offset.



30
31
32
# File 'lib/pagy/classes/offset/offset.rb', line 30

def offset
  @offset
end

#previousObject (readonly)

Returns the value of attribute previous.



30
31
32
# File 'lib/pagy/classes/offset/offset.rb', line 30

def previous
  @previous
end

#toObject (readonly)

Returns the value of attribute to.



30
31
32
# File 'lib/pagy/classes/offset/offset.rb', line 30

def to
  @to
end

Instance Method Details

#records(collection) ⇒ Object



33
34
35
# File 'lib/pagy/classes/offset/offset.rb', line 33

def records(collection)
  collection.offset(@offset).limit(@limit)
end