Module: Neo4j::WillPaginate::Pagination

Includes:
WillPaginate::CollectionMethods
Defined in:
lib/neo4j-will_paginate.rb

Overview

The module provides the common interface for the pagination on any Enumerable class. By including the module, #paginate method will be available.

Instance Method Summary collapse

Instance Method Details

#paginate(options = {}) ⇒ Object

Paginates the Enumerable and returns WillPaginate::Collection instance.

Examples:

Paginate on a relationship:

person.friends.paginate(:page => 5, :per_page => 10)

Paginate the search results:

Person.all(:conditions => "name: Dmytrii*").paginate(:page => 5, :per_page => 10)

Parameters:

  • options (Hash) (defaults to: {})

    a hash of options for the pagination.

Options Hash (options):

  • :page (Symbol)

    current page for the pagination (defualts to 1).

  • :per_page (Symbol)

    numer of items per page (defaults to WillPaginate.per_page). Aliases are ‘:per`, `:limit`.



27
28
29
30
31
32
33
34
35
# File 'lib/neo4j-will_paginate.rb', line 27

def paginate(options={})
  page      = (options[:page] || 1).to_i
  per_page  = (options[:per] || options[:per_page] || options[:limit] || ::WillPaginate.per_page).to_i
  ::WillPaginate::Collection.create(page, per_page) do |pager|
    res = ::Neo4j::Paginated.create_from(self, page, per_page)
    pager.replace res.to_a
    pager.total_entries = res.total unless pager.total_entries
  end
end