Module: WillPaginate::DataMapper::Pagination

Defined in:
lib/will_paginate/data_mapper.rb

Instance Method Summary collapse

Instance Method Details

#page(num) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/will_paginate/data_mapper.rb', line 10

def page(num)
  pagenum = ::WillPaginate::PageNumber(num.nil? ? 1 : num)
  per_page = query.limit || self.per_page
  options = {:offset => pagenum.to_offset(per_page).to_i}
  options[:limit] = per_page unless query.limit
  col = new_collection(query.merge(options))
  col.current_page = pagenum
  col
end

#paginate(options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/will_paginate/data_mapper.rb', line 20

def paginate(options)
  options  = options.dup
  pagenum  = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
  per_page = options.delete(:per_page) || self.per_page

  options.delete(:page)
  options[:limit] = per_page.to_i

  all(options).page(pagenum)
end