Sha256: 6ddaeb011e93d20abefa6e09558cb39c5c7919d1d7ccbeed4a1147d9741a47f4
Contents?: true
Size: 751 Bytes
Versions: 4
Compression:
Stored size: 751 Bytes
Contents
# encoding: utf-8 require "dm-aggregates" module DataMapper module Model # @since 0.0.2 # @example Post.paginate(page, order: [:updated_at.desc]) def paginate(pagenum = 1, options = Hash.new) pagenum = 1 if pagenum.nil? page = self.page(pagenum.to_i, options) Page.current = page offset = page.number(:db) * page.per_page self.all(options.merge!(offset: offset, limit: page.per_page)) end # @since 0.0.2 def page(current, options = Hash.new) per_page = defined?(PER_PAGE) ? PER_PAGE : 10 # the count options are very important # Product.count vs. Product.count(online: true) Page.new(current: current, count: self.count(options), per_page: per_page) end end end
Version data entries
4 entries across 4 versions & 1 rubygems