Sha256: dfe6e58f1c4673af398ee3e6642b96cdb9eacdd4afd77cde9aab4ef0fd0c9bb2

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 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
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pagers-3.0.0 lib/pagers/active_record/relation.rb