Module: Kaminari::PageScopeMethods

Defined in:
lib/dont_you_count/kaminari.rb

Instance Method Summary collapse

Instance Method Details

#total_count(column_name = :all, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dont_you_count/kaminari.rb', line 4

def total_count(column_name = :all, options = {})
  if ActiveAdmin.application.dont_count.include?(entry_name)
    2000000
  else
    @total_count ||= begin
      c = except(:offset, :limit, :order)

      # Remove includes only if they are irrelevant
      c = c.except(:includes) unless references_eager_loaded_tables?

      # Rails 4.1 removes the `options` argument from AR::Relation#count
      args = [column_name]
      args << options if ActiveRecord::VERSION::STRING < '4.1.0'

      # .group returns an OrderdHash that responds to #count
      c = c.count(*args)
      if c.is_a?(Hash) || c.is_a?(ActiveSupport::OrderedHash)
        c.count
      else
        c.respond_to?(:count) ? c.count(*args) : c
      end
    end
  end
end