Module: Redis::Objects::Counters::InstanceMethods

Defined in:
lib/redis/objects/counters.rb

Overview

Instance methods that appear in your class when you include Redis::Objects.

Instance Method Summary collapse

Instance Method Details

#decrement(name, by = 1) ⇒ Object

Decrement a counter. Called mainly in the context of :counter_cache


145
146
147
148
149
150
151
# File 'lib/redis/objects/counters.rb', line 145

def decrement(name, by=1)
  if self.class.counter_defined?(name)
    send(name).decrement(by)
  else
    super # ActiveRecord
  end
end

#increment(name, by = 1) ⇒ Object

Increment a counter. Called mainly in the context of :counter_cache


136
137
138
139
140
141
142
# File 'lib/redis/objects/counters.rb', line 136

def increment(name, by=1)
  if self.class.counter_defined?(name)
    send(name).increment(by)
  else
    super # ActiveRecord
  end
end