class Counter::Cache::Counters::BufferCounter::Updater

Public Instance Methods

update!(direction) click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 10
def update!(direction)
  return unless valid?
  incr if direction == :incr
  decr if direction == :decr
  enqueue
end

Private Instance Methods

decr() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 39
def decr
  redis.decr(key, increment_by)
end
enqueue() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 19
def enqueue
  Enqueuer.new(options,
               source_object.class.name,
               relation_finder.relation_id,
               relation_finder.relation_class,
               counter_class_name).enqueue!(source_object)
end
incr() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 35
def incr
  redis.incr(key, increment_by)
end
increment_by() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 43
def increment_by
  return options.increment_by.call(source_object) if options.increment_by.is_a?(Proc)
  1
end
key() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 48
def key
  Key.new(source_object, options).to_s
end
redis() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 52
def redis
  Counter::Cache::Redis.new
end
relation_finder() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 27
def relation_finder
  RelationFinder.new(source_object, options)
end
valid?() click to toggle source
# File lib/counter/cache/counters/buffer_counter/updater.rb, line 31
def valid?
  (!options.if_value || options.if_value.call(source_object)) && !relation_finder.relation_id.nil?
end