Class: Mongoid::Paginator

Inherits:
Object show all
Defined in:
lib/mongoid/paginator.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Paginator

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.



9
10
11
12
13
# File 'lib/mongoid/paginator.rb', line 9

def initialize(options = {})
  page = options[:page]
  @limit = options[:per_page] || 20
  @offset = page ? (page - 1) * @limit : 0
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'lib/mongoid/paginator.rb', line 4

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



4
5
6
# File 'lib/mongoid/paginator.rb', line 4

def offset
  @offset
end

Instance Method Details

#optionsObject

Generate the options needed for returning the correct results given the supplied parameters



17
18
19
# File 'lib/mongoid/paginator.rb', line 17

def options
  { :limit => @limit, :offset => @offset }
end