Class: Capacitor::CounterCache

Inherits:
Object
  • Object
show all
Defined in:
lib/capacitor/counter_cache.rb

Overview

Public: The public interface to incrementing and decrementing the counter cache

klass - ActiveRecord class id - record id column - counter column symbol

Instance Method Summary collapse

Constructor Details

#initialize(klass, id, column) ⇒ CounterCache

Returns a new instance of CounterCache.



8
9
10
11
12
# File 'lib/capacitor/counter_cache.rb', line 8

def initialize(klass, id, column)
  @classname = klass.to_s
  @id = id.to_s
  @column = column
end

Instance Method Details

#decrementObject

Public: decrement ‘column` by 1

Returns: nothing



24
25
26
# File 'lib/capacitor/counter_cache.rb', line 24

def decrement
  enqueue_count_change -1
end

#incrementObject

Public: increment ‘column` by 1

Returns: nothing



17
18
19
# File 'lib/capacitor/counter_cache.rb', line 17

def increment
  enqueue_count_change 1
end