Created
November 28, 2018 07:40
-
-
Save willnet/5ee69c90312f9d7e5db786937248852f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WrapperForKaminari | |
attr_reader :total_count, :per, :page | |
delegate_missing_to :@models | |
def initialize(models:, total_count:, per:, page:) | |
@models = models | |
@total_count = total_count | |
@per = per | |
@page = page | |
end | |
def total_pages | |
(total_count / per) + 1 | |
end | |
def current_page | |
page | |
end | |
def last_page? | |
current_page == total_pages | |
end | |
def out_of_range? | |
current_page > total_pages | |
end | |
def limit_value | |
per | |
end | |
def next_page | |
current_page + 1 unless last_page? || out_of_range? | |
end | |
def prev_page | |
current_page - 1 unless first_page? || out_of_range? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment