Sha256: e1c90fbc0a117070246a5de74d6a1c51b0bd8d2e4e6374b0dad9faf470e380c7
Contents?: true
Size: 874 Bytes
Versions: 1
Compression:
Stored size: 874 Bytes
Contents
# encoding: utf-8 require "dm-aggregates" module Rango module Pagination 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rango-0.2.1.pre | lib/rango/contrib/pagination/adapters/datamapper.rb |