Module: Kaminari::PageScopeMethods
- Included in:
- DataMapperExtension::Paginating, PluckyCriteriaMethods
- Defined in:
- lib/kaminari/models/page_scope_methods.rb
Instance Method Summary collapse
-
#current_page ⇒ Object
Current page number.
-
#first_page? ⇒ Boolean
First page of the collection ?.
-
#last_page? ⇒ Boolean
Last page of the collection?.
- #padding(num) ⇒ Object
-
#per(num) ⇒ Object
Specify the
per_page
value for the precedingpage
scope Model.page(3).per(10). -
#total_pages ⇒ Object
(also: #num_pages)
Total number of pages.
Instance Method Details
#current_page ⇒ Object
Current page number
27 28 29 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 27 def current_page (offset_value / limit_value) + 1 end |
#first_page? ⇒ Boolean
First page of the collection ?
32 33 34 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 32 def first_page? current_page == 1 end |
#last_page? ⇒ Boolean
Last page of the collection?
37 38 39 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 37 def last_page? current_page >= total_pages end |
#padding(num) ⇒ Object
15 16 17 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 15 def padding(num) offset(offset_value + num.to_i) end |
#per(num) ⇒ Object
Specify the per_page
value for the preceding page
scope
Model.page(3).per(10)
5 6 7 8 9 10 11 12 13 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 5 def per(num) if (n = num.to_i) <= 0 self elsif max_per_page && max_per_page < n limit(max_per_page).offset(offset_value / limit_value * max_per_page) else limit(n).offset(offset_value / limit_value * n) end end |
#total_pages ⇒ Object Also known as: num_pages
Total number of pages
20 21 22 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 20 def total_pages (total_count.to_f / limit_value).ceil end |