Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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