Module: Pagers::ActiveRecord::Relation

Extended by:
ActiveSupport::Concern
Defined in:
lib/pagers/active_record/relation.rb

Instance Method Summary collapse

Instance Method Details

#first_pageObject



18
19
20
# File 'lib/pagers/active_record/relation.rb', line 18

def first_page
  1
end

#last_pageObject



22
23
24
# File 'lib/pagers/active_record/relation.rb', line 22

def last_page
  total_pages
end

#next_pageObject



14
15
16
# File 'lib/pagers/active_record/relation.rb', line 14

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

#out_of_bounds?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/pagers/active_record/relation.rb', line 26

def out_of_bounds?
  @out_of_bounds ||= (current_page > total_pages || current_page < first_page)
end

#previous_pageObject



10
11
12
# File 'lib/pagers/active_record/relation.rb', line 10

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

#total_countObject



30
31
32
33
34
35
36
37
# File 'lib/pagers/active_record/relation.rb', line 30

def total_count
  @total_count ||= begin
    r = except(:limit, :offset, :order, :reorder)
    r = r.except(:includes) unless references_eager_loaded_tables?
    r = r.count
    (r.respond_to?(:count) ? r.count : r) - padding
  end
end

#total_pagesObject



6
7
8
# File 'lib/pagers/active_record/relation.rb', line 6

def total_pages
  @total_pages ||= [(total_count.to_f / page_length).ceil, 1].max
end