Sha256: e51697a66b1d95eb800ebf925dfa880b57389c90bc509eb5e2e676d862212a47
Contents?: true
Size: 1011 Bytes
Versions: 5
Compression:
Stored size: 1011 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Contexts #:nodoc: module Paging # Paginates the documents. # # Example: # # <tt>context.paginate</tt> # # Returns: # # A collection of documents paginated. def paginate @collection ||= execute WillPaginate::Collection.create(page, per_page, count) do |pager| pager.replace(@collection) end end # Either returns the page option and removes it from the options, or # returns a default value of 1. # # Returns: # # An +Integer+ page number. def page skips, limits = @options[:skip], @options[:limit] (skips && limits) ? (skips + limits) / limits : 1 end # Get the number of results per page or the default of 20. # # Returns: # # The +Integer+ number of documents in each page. def per_page (@options[:limit] || 20).to_i end end end end
Version data entries
5 entries across 5 versions & 1 rubygems