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

Instance Method Details

#current_pageObject



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_pageObject



32
33
34
# File 'lib/tire/results/pagination.rb', line 32

def next_page
  current_page < total_pages ? (current_page + 1) : nil
end

#offsetObject 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

Returns:

  • (Boolean)


40
41
42
# File 'lib/tire/results/pagination.rb', line 40

def out_of_bounds?
  current_page > total_pages
end

#per_pageObject 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_pageObject



28
29
30
# File 'lib/tire/results/pagination.rb', line 28

def previous_page
  current_page > 1 ? (current_page - 1) : nil
end

#total_entriesObject Also known as: total_count



8
9
10
# File 'lib/tire/results/pagination.rb', line 8

def total_entries
  @total
end

#total_pagesObject 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