Class: Gitlab::Pagination::Keyset::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/pagination/keyset/page.rb

Overview

A Page models the pagination information for a particular page of the collection

Constant Summary collapse

DEFAULT_PAGE_SIZE =

Default number of records for a page

20
MAXIMUM_PAGE_SIZE =

Maximum number of records for a page

100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order_by: {}, lower_bounds: nil, per_page: DEFAULT_PAGE_SIZE) ⇒ Page

Returns a new instance of Page.


17
18
19
20
21
# File 'lib/gitlab/pagination/keyset/page.rb', line 17

def initialize(order_by: {}, lower_bounds: nil, per_page: DEFAULT_PAGE_SIZE)
  @order_by = order_by.symbolize_keys
  @lower_bounds = lower_bounds&.symbolize_keys
  @per_page = per_page
end

Instance Attribute Details

#lower_boundsObject

Returns the value of attribute lower_bounds


14
15
16
# File 'lib/gitlab/pagination/keyset/page.rb', line 14

def lower_bounds
  @lower_bounds
end

#order_byObject (readonly)

Returns the value of attribute order_by


15
16
17
# File 'lib/gitlab/pagination/keyset/page.rb', line 15

def order_by
  @order_by
end

Instance Method Details

#next(lower_bounds) ⇒ Object

Construct a Page for the next page Uses identical order_by/per_page information for the next page


32
33
34
35
36
# File 'lib/gitlab/pagination/keyset/page.rb', line 32

def next(lower_bounds)
  dup.tap do |next_page|
    next_page.lower_bounds = lower_bounds&.symbolize_keys
  end
end

#per_pageObject

Number of records to return per page


24
25
26
27
28
# File 'lib/gitlab/pagination/keyset/page.rb', line 24

def per_page
  return DEFAULT_PAGE_SIZE if @per_page <= 0

  [@per_page, MAXIMUM_PAGE_SIZE].min
end