Class: Mongoid::Paginator
Overview
:nodoc:
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Paginator
constructor
Create the new Paginator with the supplied options.
-
#options ⇒ Object
Generate the options needed for returning the correct results given the supplied parameters.
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( = {}) page = [:page] @limit = [:per_page] || 20 @offset = page ? (page - 1) * @limit : 0 end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/mongoid/paginator.rb', line 4 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
4 5 6 |
# File 'lib/mongoid/paginator.rb', line 4 def offset @offset end |
Instance Method Details
#options ⇒ Object
Generate the options needed for returning the correct results given the supplied parameters
17 18 19 |
# File 'lib/mongoid/paginator.rb', line 17 def { :limit => @limit, :offset => @offset } end |