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?.
-
#next_page ⇒ Object
Next page number in the collection.
- #num_pages ⇒ Object
-
#out_of_range? ⇒ Boolean
Out of range of the collection?.
- #padding(num) ⇒ Object
-
#per(num) ⇒ Object
Specify the
per_page
value for the precedingpage
scope Model.page(3).per(10). -
#prev_page ⇒ Object
Previous page number in the collection.
-
#total_pages ⇒ Object
Total number of pages.
Instance Method Details
#current_page ⇒ Object
Current page number
40 41 42 43 44 45 46 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 40 def current_page offset_without_padding = offset_value offset_without_padding -= @_padding if defined?(@_padding) && @_padding offset_without_padding = 0 if offset_without_padding < 0 (offset_without_padding / limit_value) + 1 end |
#first_page? ⇒ Boolean
First page of the collection?
59 60 61 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 59 def first_page? current_page == 1 end |
#last_page? ⇒ Boolean
Last page of the collection?
64 65 66 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 64 def last_page? current_page >= total_pages end |
#next_page ⇒ Object
Next page number in the collection
49 50 51 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 49 def next_page current_page + 1 unless last_page? end |
#num_pages ⇒ Object
34 35 36 37 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 34 def num_pages ActiveSupport::Deprecation.warn 'num_pages is deprecated and will be removed in Kaminari 1.0. Please use total_pages instead.' total_pages end |
#out_of_range? ⇒ Boolean
Out of range of the collection?
69 70 71 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 69 def out_of_range? current_page > total_pages end |
#padding(num) ⇒ Object
15 16 17 18 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 15 def padding(num) @_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 |
#prev_page ⇒ Object
Previous page number in the collection
54 55 56 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 54 def prev_page current_page - 1 unless first_page? end |
#total_pages ⇒ Object
Total number of pages
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kaminari/models/page_scope_methods.rb', line 21 def total_pages count_without_padding = total_count count_without_padding -= @_padding if defined?(@_padding) && @_padding count_without_padding = 0 if count_without_padding < 0 total_pages_count = (count_without_padding.to_f / limit_value).ceil if max_pages.present? && max_pages < total_pages_count max_pages else total_pages_count end end |