Sha256: 00bc70988167de06d4b5792b987bc2c8136ca467217ea9e0b6a2692b0f825870

Contents?: true

Size: 627 Bytes

Versions: 5

Compression:

Stored size: 627 Bytes

Contents

module Mongoid #:nodoc:
  class Paginator #:nodoc:

    attr_reader :limit, :offset

    # Create the new Paginator with the supplied options. 
    # * Will default to offset 0 if no page defined in the options.
    # * Will default to limit 20 if no per_page defined in the options.
    def initialize(options = {})
      page = options[:page]
      @limit = options[:per_page] || 20
      @offset = page ? (page - 1) * @limit : 0
    end

    # Generate the options needed for returning the correct
    # results given the supplied parameters
    def options
      { :limit => @limit, :offset => @offset }
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
durran-mongoid-0.2.0 lib/mongoid/paginator.rb
durran-mongoid-0.2.2 lib/mongoid/paginator.rb
durran-mongoid-0.2.3 lib/mongoid/paginator.rb
durran-mongoid-0.2.4 lib/mongoid/paginator.rb
mongoid-0.2.5 lib/mongoid/paginator.rb