Class: Gitlab::PaginationDelegate

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/pagination_delegate.rb

Overview

rubocop:disable Gitlab/NamespacedClass

Constant Summary collapse

DEFAULT_PER_PAGE =
Kaminari.config.default_per_page
MAX_PER_PAGE =
Kaminari.config.max_per_page

Instance Method Summary collapse

Constructor Details

#initialize(page:, per_page:, count:, options: {}) ⇒ PaginationDelegate

Returns a new instance of PaginationDelegate.



8
9
10
11
12
13
14
15
# File 'lib/gitlab/pagination_delegate.rb', line 8

def initialize(page:, per_page:, count:, options: {})
  @count = count
  @options = { default_per_page: DEFAULT_PER_PAGE,
               max_per_page: MAX_PER_PAGE }.merge(options)

  @per_page = sanitize_per_page(per_page)
  @page = sanitize_page(page)
end

Instance Method Details

#current_pageObject



33
34
35
# File 'lib/gitlab/pagination_delegate.rb', line 33

def current_page
  @page
end

#first_page?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/gitlab/pagination_delegate.rb', line 41

def first_page?
  current_page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/gitlab/pagination_delegate.rb', line 45

def last_page?
  current_page >= total_pages
end

#limit_valueObject



37
38
39
# File 'lib/gitlab/pagination_delegate.rb', line 37

def limit_value
  @per_page
end

#next_pageObject



25
26
27
# File 'lib/gitlab/pagination_delegate.rb', line 25

def next_page
  current_page + 1 unless last_page?
end

#offsetObject



49
50
51
# File 'lib/gitlab/pagination_delegate.rb', line 49

def offset
  (current_page - 1) * limit_value
end

#prev_pageObject



29
30
31
# File 'lib/gitlab/pagination_delegate.rb', line 29

def prev_page
  current_page - 1 unless first_page?
end

#total_countObject



17
18
19
# File 'lib/gitlab/pagination_delegate.rb', line 17

def total_count
  @count
end

#total_pagesObject



21
22
23
# File 'lib/gitlab/pagination_delegate.rb', line 21

def total_pages
  (total_count.to_f / @per_page).ceil
end