Module: Rango::Pagination::Sequel::Dataset

Defined in:
lib/rango/contrib/pagination/adapters/sequel.rb

Instance Method Summary collapse

Instance Method Details

#paginate(current = 1, per_page = Page.per_page, options = nil) ⇒ Object

Examples:

Sticker.paginate(page, 20, online: false)
Sticker.filter(online: false).paginate(page)

Since:

  • 0.2.2



11
12
13
14
15
16
# File 'lib/rango/contrib/pagination/adapters/sequel.rb', line 11

def paginate(current = 1, per_page = Page.per_page, options = nil)
  current = current ? current.to_i : 1 # current can be nil or "1"
  page = Page.new(current: current, count: self.count, per_page: per_page)
  dataset = options ? self.filter(options) : self
  return page, dataset.limit(per_page, (current - 1) * per_page)
end