Module: PeijiSan::PaginationMethods
- Defined in:
- lib/peiji_san.rb
Overview
The page scope is extended with the PaginationMethods. This means that all methods defined on this module will be available on the resulting collection.
collection = Member.active.page(1)
collection.has_next_page?
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#entries_per_page ⇒ Object
Returns the value of attribute entries_per_page.
-
#scope_without_pagination ⇒ Object
Returns the value of attribute scope_without_pagination.
Instance Method Summary collapse
-
#current_page?(page) ⇒ Boolean
Returns whether or not the given page is the current page.
-
#has_next_page? ⇒ Boolean
Returns whether or not there is a next page for the current scope.
-
#has_previous_page? ⇒ Boolean
Returns whether or not there is a previous page for the current scope.
-
#next_page ⇒ Object
Returns the next page number if there is a next page, returns
nil
otherwise. -
#page_count ⇒ Object
Returns the number of pages for the current scope.
-
#previous_page ⇒ Object
Returns the previous page number if there is a previous page, returns
nil
otherwise. -
#unpaged_count ⇒ Object
Returns the row count for all the rows that would match the current scope, so not only on the current page.
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
26 27 28 |
# File 'lib/peiji_san.rb', line 26 def current_page @current_page end |
#entries_per_page ⇒ Object
Returns the value of attribute entries_per_page.
26 27 28 |
# File 'lib/peiji_san.rb', line 26 def entries_per_page @entries_per_page end |
#scope_without_pagination ⇒ Object
Returns the value of attribute scope_without_pagination.
26 27 28 |
# File 'lib/peiji_san.rb', line 26 def scope_without_pagination @scope_without_pagination end |
Instance Method Details
#current_page?(page) ⇒ Boolean
Returns whether or not the given page is the current page.
29 30 31 |
# File 'lib/peiji_san.rb', line 29 def current_page?(page) @current_page == page end |
#has_next_page? ⇒ Boolean
Returns whether or not there is a next page for the current scope.
34 35 36 |
# File 'lib/peiji_san.rb', line 34 def has_next_page? @current_page < page_count end |
#has_previous_page? ⇒ Boolean
Returns whether or not there is a previous page for the current scope.
39 40 41 |
# File 'lib/peiji_san.rb', line 39 def has_previous_page? @current_page != 1 end |
#next_page ⇒ Object
Returns the next page number if there is a next page, returns nil
otherwise.
45 46 47 |
# File 'lib/peiji_san.rb', line 45 def next_page @current_page + 1 if has_next_page? end |
#page_count ⇒ Object
Returns the number of pages for the current scope.
62 63 64 |
# File 'lib/peiji_san.rb', line 62 def page_count (unpaged_count.to_f / @entries_per_page).ceil end |
#previous_page ⇒ Object
Returns the previous page number if there is a previous page, returns nil
otherwise.
51 52 53 |
# File 'lib/peiji_san.rb', line 51 def previous_page @current_page - 1 if has_previous_page? end |
#unpaged_count ⇒ Object
Returns the row count for all the rows that would match the current scope, so not only on the current page.
57 58 59 |
# File 'lib/peiji_san.rb', line 57 def unpaged_count scope_without_pagination.count end |