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

Class Method Details

.default_per_pageObject



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

def default_per_page
  10
end

Instance Method Details

#current_pageObject



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

Returns:

  • (Boolean)


57
58
59
# File 'lib/tire/results/pagination.rb', line 57

def first_page?
  current_page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/tire/results/pagination.rb', line 61

def last_page?
  current_page == total_pages
end

#next_pageObject



37
38
39
# File 'lib/tire/results/pagination.rb', line 37

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

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

Returns:

  • (Boolean)


45
46
47
# File 'lib/tire/results/pagination.rb', line 45

def out_of_bounds?
  current_page > total_pages
end

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



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

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

#total_entriesObject Also known as: total_count



13
14
15
# File 'lib/tire/results/pagination.rb', line 13

def total_entries
  @total
end

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