Class: Gitlab::PaginationDelegate
- Inherits:
-
Object
- Object
- Gitlab::PaginationDelegate
- 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
- #current_page ⇒ Object
- #first_page? ⇒ Boolean
-
#initialize(page:, per_page:, count:, options: {}) ⇒ PaginationDelegate
constructor
A new instance of PaginationDelegate.
- #last_page? ⇒ Boolean
- #limit_value ⇒ Object
- #next_page ⇒ Object
- #offset ⇒ Object
- #prev_page ⇒ Object
- #total_count ⇒ Object
- #total_pages ⇒ Object
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() @per_page = sanitize_per_page(per_page) @page = sanitize_page(page) end |
Instance Method Details
#current_page ⇒ Object
33 34 35 |
# File 'lib/gitlab/pagination_delegate.rb', line 33 def current_page @page end |
#first_page? ⇒ Boolean
41 42 43 |
# File 'lib/gitlab/pagination_delegate.rb', line 41 def first_page? current_page == 1 end |
#last_page? ⇒ Boolean
45 46 47 |
# File 'lib/gitlab/pagination_delegate.rb', line 45 def last_page? current_page >= total_pages end |
#limit_value ⇒ Object
37 38 39 |
# File 'lib/gitlab/pagination_delegate.rb', line 37 def limit_value @per_page end |
#next_page ⇒ Object
25 26 27 |
# File 'lib/gitlab/pagination_delegate.rb', line 25 def next_page current_page + 1 unless last_page? end |
#offset ⇒ Object
49 50 51 |
# File 'lib/gitlab/pagination_delegate.rb', line 49 def offset (current_page - 1) * limit_value end |
#prev_page ⇒ Object
29 30 31 |
# File 'lib/gitlab/pagination_delegate.rb', line 29 def prev_page current_page - 1 unless first_page? end |
#total_count ⇒ Object
17 18 19 |
# File 'lib/gitlab/pagination_delegate.rb', line 17 def total_count @count end |
#total_pages ⇒ Object
21 22 23 |
# File 'lib/gitlab/pagination_delegate.rb', line 21 def total_pages (total_count.to_f / @per_page).ceil end |