Sha256: 4fbcb6860e2ebc9e302331903246bcdc18c3d75a3eff6c6d08e4cf284a8de692
Contents?: true
Size: 1.09 KB
Versions: 4
Compression:
Stored size: 1.09 KB
Contents
# Borrowed from # https://raw.github.com/dbackeus/will_paginate/master/lib/will_paginate/mongoid.rb # until it makes it into will_paginate require 'mongoid' require 'will_paginate/collection' module WillPaginate module Mongoid module CriteriaMethods def paginate(options = {}) extend CollectionMethods @current_page = WillPaginate::PageNumber(options[:page] || @current_page || 1) @page_multiplier = current_page - 1 pp = (options[:per_page] || per_page || WillPaginate.per_page).to_i limit(pp).skip(@page_multiplier * pp) end def per_page(value = :non_given) value == :non_given ? options[:limit] : limit(value) end def page(page) paginate(:page => page) end end module CollectionMethods attr_reader :current_page def total_entries @total_entries ||= count end def total_pages (total_entries / per_page.to_f).ceil end def offset @page_multiplier * per_page end end ::Mongoid::Criteria.send(:include, CriteriaMethods) end end
Version data entries
4 entries across 4 versions & 1 rubygems