Module: Pagers::Extensions::ActiveRecord::Relation

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

Instance Method Summary collapse

Instance Method Details

#first_pageObject



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

def first_page
  1
end

#last_pageObject



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

def last_page
  total_pages
end

#next_pageObject



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

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

#out_of_bounds?Boolean

Returns:

  • (Boolean)


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

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

#previous_pageObject



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

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

#total_countObject



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

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

#total_pagesObject



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

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