Sha256: 3b1f7ae874de83137498ffde37d3f12a2a506b01056df5870ff3dbe020e2b76b
Contents?: true
Size: 929 Bytes
Versions: 7
Compression:
Stored size: 929 Bytes
Contents
module Pagers module ActiveRecord module Relation extend ActiveSupport::Concern def total_pages @total_pages ||= [(total_count.to_f / page_length).ceil, 1].max end def previous_page @previous_page ||= current_page > 1 ? (current_page - 1) : nil end def next_page @next_page ||= current_page < total_pages ? (current_page + 1) : nil end def first_page 1 end def last_page total_pages end def out_of_bounds? @out_of_bounds ||= (current_page > total_pages || current_page < first_page) end 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 end end end
Version data entries
7 entries across 7 versions & 1 rubygems