Module: MerbPaginate::Finders::Datamapper::ClassMethods

Includes:
GenericOrmMethods
Defined in:
lib/merb_paginate/finders/sequel.rb,
lib/merb_paginate/finders/datamapper.rb

Instance Method Summary collapse

Instance Method Details

#paginate(options = {}) ⇒ Object

This is the main paginating finder.

Special parameters for paginating finders

  • :page – REQUIRED, but defaults to 1 if false or nil

  • :per_page – defaults to CurrentModel.per_page (which is 30 if not overridden)

  • :total_entries – use only if you manually count total entries

  • :count – additional options that are passed on to count

All other options (conditions, order, …) are forwarded to all and count calls.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/merb_paginate/finders/datamapper.rb', line 29

def paginate(options = {})
  Merb.logger.info(" $$$ Sequel support in merb_paginate has not been tested at all. Please let me know if it works.")
  page, per_page, total_entries = wp_parse_options(options)

  WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
    count_options = options.except :page, :per_page, :total_entries
    find_options = count_options.except(:count).update(:offset => pager.offset, :limit => pager.per_page) 
      
    pager.replace all(find_options)
      
    # magic counting for user convenience:
    pager.total_entries = wp_count(count_options) unless pager.total_entries
  end
end