Module: ActiveRecord::Counting

Extended by:
ActiveSupport::Concern
Included in:
Relation
Defined in:
lib/rails-counting.rb

Instance Method Summary collapse

Instance Method Details

#count_with_counting(*args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
# 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) ⇒ Object



24
25
26
# File 'lib/rails-counting.rb', line 24

def counting(&block)
  spawn.counting! &block
end

#counting!(&block) ⇒ Object



28
29
30
31
32
# File 'lib/rails-counting.rb', line 28

def counting!(&block)
  @counting_values ||= []
  @counting_values << block
  self
end