Module: VisitCounter::InstanceMethods

Defined in:
lib/visit-counter/visit_counter.rb

Instance Method Summary collapse

Instance Method Details

#get_counter_delta(name) ⇒ Object



24
25
26
27
# File 'lib/visit-counter/visit_counter.rb', line 24

def get_counter_delta(name)
  key = VisitCounter::Key.key(self, name)
  VisitCounter::Store.engine.get(key)
end

#incr_counter(name) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/visit-counter/visit_counter.rb', line 15

def incr_counter(name)
  key = VisitCounter::Key.key(self, name)
  count = VisitCounter::Store.engine.incr(key)
  staged_count = self.send(:read_attribute, name).to_i
  if Helper.passed_limit?(self, staged_count, count, name)
    Helper.persist(self, staged_count, count, name)
  end
end

#nullify_counter_cache(name) ⇒ Object



36
37
38
39
# File 'lib/visit-counter/visit_counter.rb', line 36

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

#read_counter(name) ⇒ Object



29
30
31
32
33
34
# File 'lib/visit-counter/visit_counter.rb', line 29

def read_counter(name)
  current_count = self.send(:read_attribute, name).to_i
  count = get_counter_delta(name)

  current_count + count
end