Class: Pragma::Decorator::Pagination::Adapter::WillPaginate Private

Inherits:
Base
  • Object
show all
Includes:
Adaptor
Defined in:
lib/pragma/decorator/pagination/adapter/will_paginate.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This adapter provides support for retrieving pagination information from collections paginated with will_paginate.

Instance Attribute Summary

Attributes inherited from Base

#collection

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Pragma::Decorator::Pagination::Adapter::Base

Class Method Details

.supports?(collection) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this adapter supports the given collection.

Esnures that the WillPaginate constant is defined and that the collection responds to #previous_page.

Returns:

  • (Boolean)

    whether the adapter supports the given collection

See Also:

  • Adapter.load_adaptor


23
24
25
# File 'lib/pragma/decorator/pagination/adapter/will_paginate.rb', line 23

def supports?(collection)
  Object.const_defined?('WillPaginate') && collection.respond_to?(:previous_page)
end

Instance Method Details

#current_pageInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the number of the current page.

Returns:

  • (Integer)

    the number of the current page



59
60
61
# File 'lib/pragma/decorator/pagination/adapter/will_paginate.rb', line 59

def current_page
  collection.current_page
end

#next_pageInteger|NilClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the number of the next page, if any.

Returns:

  • (Integer|NilClass)

    the number of the next page, if any



66
67
68
# File 'lib/pragma/decorator/pagination/adapter/will_paginate.rb', line 66

def next_page
  collection.next_page
end

#per_pageInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the number of entries per page in the collection.

Returns:

  • (Integer)

    the number of entries per page in the collection



38
39
40
# File 'lib/pragma/decorator/pagination/adapter/will_paginate.rb', line 38

def per_page
  collection.per_page
end

#previous_pageInteger|NilClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the number of the previous page, if any.

Returns:

  • (Integer|NilClass)

    the number of the previous page, if any



52
53
54
# File 'lib/pragma/decorator/pagination/adapter/will_paginate.rb', line 52

def previous_page
  collection.previous_page
end

#total_entriesInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the total number of entries in the collection.

Returns:

  • (Integer)

    the total number of entries in the collection



31
32
33
# File 'lib/pragma/decorator/pagination/adapter/will_paginate.rb', line 31

def total_entries
  collection.total_entries
end

#total_pagesInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the total number of pages in the collection.

Returns:

  • (Integer)

    the total number of pages in the collection



45
46
47
# File 'lib/pragma/decorator/pagination/adapter/will_paginate.rb', line 45

def total_pages
  collection.total_pages
end