Module: WillPaginate::Mongoid::CriteriaMethods

Defined in:
lib/will_paginate/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#page(page) ⇒ Object


23
24
25
# File 'lib/will_paginate/mongoid.rb', line 23

def page(page)
  paginate(:page => page)
end

#paginate(options = {}) ⇒ Object


7
8
9
10
11
12
13
# File 'lib/will_paginate/mongoid.rb', line 7

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

#per_page(value = :non_given) ⇒ Object


15
16
17
18
19
20
21
# File 'lib/will_paginate/mongoid.rb', line 15

def per_page(value = :non_given)
  if value == :non_given
    options[:limit] == 0 ? nil : options[:limit] # in new Mongoid versions a nil limit is saved as 0
  else
    limit(value)
  end
end