Module: Tire::Results::Pagination
- Included in:
- Collection
- Defined in:
- lib/tire/results/pagination.rb
Overview
Adds support for WillPaginate and Kaminari
Instance Method Summary collapse
- #current_page ⇒ Object
- #next_page ⇒ Object
- #offset ⇒ Object (also: #offset_value)
- #out_of_bounds? ⇒ Boolean
- #per_page ⇒ Object (also: #limit_value)
- #previous_page ⇒ Object
- #total_entries ⇒ Object (also: #total_count)
- #total_pages ⇒ Object (also: #num_pages)
Instance Method Details
#current_page ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/tire/results/pagination.rb', line 20 def current_page if @options[:page] @options[:page].to_i else (per_page + @options[:from].to_i) / per_page end end |
#next_page ⇒ Object
32 33 34 |
# File 'lib/tire/results/pagination.rb', line 32 def next_page current_page < total_pages ? (current_page + 1) : nil end |
#offset ⇒ Object Also known as: offset_value
36 37 38 |
# File 'lib/tire/results/pagination.rb', line 36 def offset per_page * (current_page - 1) end |
#out_of_bounds? ⇒ Boolean
40 41 42 |
# File 'lib/tire/results/pagination.rb', line 40 def out_of_bounds? current_page > total_pages end |
#per_page ⇒ Object Also known as: limit_value
12 13 14 |
# File 'lib/tire/results/pagination.rb', line 12 def per_page (@options[:per_page] || @options[:size] || 10 ).to_i end |
#previous_page ⇒ Object
28 29 30 |
# File 'lib/tire/results/pagination.rb', line 28 def previous_page current_page > 1 ? (current_page - 1) : nil end |
#total_entries ⇒ Object Also known as: total_count
8 9 10 |
# File 'lib/tire/results/pagination.rb', line 8 def total_entries @total end |
#total_pages ⇒ Object Also known as: num_pages
16 17 18 |
# File 'lib/tire/results/pagination.rb', line 16 def total_pages ( @total.to_f / per_page ).ceil end |