class ROM::LDAP::Plugin::Pagination::Pager

Pager object provides the underlying pagination API for relations

@api public

Public Instance Methods

at(dataset, current_page, per_page = self.per_page) click to toggle source

@api private

# File lib/rom/ldap/plugin/pagination.rb, line 82
def at(dataset, current_page, per_page = self.per_page)
  current_page = current_page.to_i
  per_page     = per_page.to_i
  offset       = (current_page - 1) * per_page

  self.class.new(
    dataset.with(offset: offset, limit: per_page),
    current_page: current_page, per_page: per_page
  )
end
next_page() click to toggle source

Return next page number

@example

users.page(2).pager.next_page
# => 3

@return [Integer]

@api public

# File lib/rom/ldap/plugin/pagination.rb, line 44
def next_page
  num = current_page + 1
  num if total_pages >= num
end
prev_page() click to toggle source

Return previous page number

@example

users.page(2).pager.prev_page
# => 1

@return [Integer]

@api public

# File lib/rom/ldap/plugin/pagination.rb, line 58
def prev_page
  num = current_page - 1
  num if num.positive?
end
total() click to toggle source

Return total number of tuples

@return [Integer]

@api public

# File lib/rom/ldap/plugin/pagination.rb, line 68
def total
  dataset.total
end
total_pages() click to toggle source

Return total number of pages

@return [Integer]

@api public

# File lib/rom/ldap/plugin/pagination.rb, line 77
def total_pages
  (total / per_page.to_f).ceil
end