module ActiveRecord::Counting

Public Instance Methods

count_with_counting(*args, &block) click to toggle source
# File lib/rails-counting.rb, line 14
def count_with_counting(*args, &block)
  if @counting_values.blank?
    count_without_counting *args, &block
  else
    @counting_values.reduce self do |arel, lambda|
      lambda.call arel
    end.count_without_counting *args, &block
  end
end
counting(&block) click to toggle source
# File lib/rails-counting.rb, line 24
def counting(&block)
  spawn.counting! &block
end
counting!(&block) click to toggle source
# File lib/rails-counting.rb, line 28
def counting!(&block)
  @counting_values ||= []
  @counting_values << block
  self
end