Module: Pagers::ActiveRecord::Relation
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pagers/active_record/relation.rb
Instance Method Summary collapse
- #first_page ⇒ Object
- #last_page ⇒ Object
- #next_page ⇒ Object
- #out_of_bounds? ⇒ Boolean
- #previous_page ⇒ Object
- #total_count ⇒ Object
- #total_pages ⇒ Object
Instance Method Details
#first_page ⇒ Object
18 19 20 |
# File 'lib/pagers/active_record/relation.rb', line 18 def first_page 1 end |
#last_page ⇒ Object
22 23 24 |
# File 'lib/pagers/active_record/relation.rb', line 22 def last_page total_pages end |
#next_page ⇒ Object
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
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_page ⇒ Object
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_count ⇒ Object
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_pages ⇒ Object
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 |