Module: VisitCounter::InstanceMethods

Defined in:
lib/visit_counter_updater/visit_counter_updater.rb

Instance Method Summary collapse

Instance Method Details

#get_counter_delta(name) ⇒ Object



14
15
16
17
# File 'lib/visit_counter_updater/visit_counter_updater.rb', line 14

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

#incr_counter(name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/visit_counter_updater/visit_counter_updater.rb', line 3

def incr_counter(name)
  key = VisitCounter::Key.new(self, name)
  set_key = VisitCounter::Key.generate(key.method, key.object_class)
  count = VisitCounter::Store.engine.incr(key.generate_from_instance, Time.now.to_i, set_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, substract = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/visit_counter_updater/visit_counter_updater.rb', line 19

def nullify_counter_cache(name, substract = nil)
  key = VisitCounter::Key.new(self, name).generate_from_instance
  if substract
    VisitCounter::Store.engine.substract(key, substract)
  else
    VisitCounter::Store.engine.nullify(key)
  end
end