Module: Pagers::Extensions::ActiveRecord::Relation
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pagers/extensions/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
19 20 21 |
# File 'lib/pagers/extensions/active_record/relation.rb', line 19 def first_page 1 end |
#last_page ⇒ Object
23 24 25 |
# File 'lib/pagers/extensions/active_record/relation.rb', line 23 def last_page total_pages end |
#next_page ⇒ Object
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
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_page ⇒ Object
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_count ⇒ Object
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_pages ⇒ Object
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 |