Module: WillPaginate::Mongoid::CriteriaMethods

Defined in:
lib/will_paginate/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#page(page) ⇒ Object



25
26
27
# File 'lib/will_paginate/mongoid.rb', line 25

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

#paginate(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# 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
  @total_entries = options.delete(:total_entries)

  pp = (options[:per_page] || per_page || WillPaginate.per_page).to_i
  limit(pp).skip(@page_multiplier * pp)
end

#per_page(value = :non_given) ⇒ Object



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

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