Module: Tire::Results::Pagination
- Included in:
- Collection
- Defined in:
- lib/tire/results/pagination.rb
Overview
Adds support for WillPaginate and Kaminari
Class Method Summary collapse
Instance Method Summary collapse
- #current_page ⇒ Object
- #first_page? ⇒ Boolean
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #offset ⇒ Object (also: #offset_value)
- #out_of_bounds? ⇒ Boolean (also: #out_of_range?)
- #per_page ⇒ Object (also: #limit_value)
- #previous_page ⇒ Object
- #total_entries ⇒ Object (also: #total_count)
- #total_pages ⇒ Object (also: #num_pages)
Class Method Details
.default_per_page ⇒ Object
8 9 10 |
# File 'lib/tire/results/pagination.rb', line 8 def default_per_page 10 end |
Instance Method Details
#current_page ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/tire/results/pagination.rb', line 25 def current_page if @options[:page] @options[:page].to_i else (per_page + @options[:from].to_i) / per_page end end |
#first_page? ⇒ Boolean
57 58 59 |
# File 'lib/tire/results/pagination.rb', line 57 def first_page? current_page == 1 end |
#last_page? ⇒ Boolean
61 62 63 |
# File 'lib/tire/results/pagination.rb', line 61 def last_page? current_page == total_pages end |
#next_page ⇒ Object
37 38 39 |
# File 'lib/tire/results/pagination.rb', line 37 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#offset ⇒ Object Also known as: offset_value
41 42 43 |
# File 'lib/tire/results/pagination.rb', line 41 def offset per_page * (current_page - 1) end |
#out_of_bounds? ⇒ Boolean Also known as: out_of_range?
45 46 47 |
# File 'lib/tire/results/pagination.rb', line 45 def out_of_bounds? current_page > total_pages end |
#per_page ⇒ Object Also known as: limit_value
17 18 19 |
# File 'lib/tire/results/pagination.rb', line 17 def per_page (@options[:per_page] || @options[:size] || default_per_page ).to_i end |
#previous_page ⇒ Object
33 34 35 |
# File 'lib/tire/results/pagination.rb', line 33 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#total_entries ⇒ Object Also known as: total_count
13 14 15 |
# File 'lib/tire/results/pagination.rb', line 13 def total_entries @total end |
#total_pages ⇒ Object Also known as: num_pages
21 22 23 |
# File 'lib/tire/results/pagination.rb', line 21 def total_pages ( @total.to_f / per_page ).ceil end |