Module: VisitCounter

Defined in:
lib/visit-counter/key.rb,
lib/visit-counter/store.rb,
lib/visit-counter/version.rb,
lib/visit-counter/visit_counter.rb

Defined Under Namespace

Classes: Key, Store

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#incr_counter(name) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/visit-counter/visit_counter.rb', line 2

def incr_counter(name)
  key = VisitCounter::Key.key(self, name)
  count = VisitCounter::Store.engine.incr(key)
  current_count = self.send(name).to_i
  if current_count / (current_count + count).to_f < 0.7
    self.update_attribute(name, current_count + count)
    nullify_counter_cache(name)
  end
end

#nullify_counter_cache(name) ⇒ Object



12
13
14
15
# File 'lib/visit-counter/visit_counter.rb', line 12

def nullify_counter_cache(name)
  key = VisitCounter::Key.key(self, name)
  VisitCounter::Store.engine.nullify(key)
end