Module: BetterCounters

Extended by:
ActiveSupport::Concern
Defined in:
lib/better_counters.rb,
lib/better_counters/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"1.0.2"

Instance Method Summary collapse

Instance Method Details

#update_counter_cache(p = {}, n = 1) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/better_counters.rb', line 6

def update_counter_cache(p = {}, n = 1)
  p.each do |c|
    if c[1]
      column = (c[1] == true) ? self.class.table_name + "_count" : c[1]
      n > 0 ? send(c[0]).increment!(column) : send(c[0]).decrement!(column)
    end
  end
end