Class: VisitCounter::Helper
- Inherits:
-
Object
- Object
- VisitCounter::Helper
- Defined in:
- lib/visit-counter/visit_counter.rb
Class Method Summary collapse
- .default_threshold(method) ⇒ Object
- .passed_limit?(object, staged_count, diff, name) ⇒ Boolean
- .persist(object, staged_count, diff, name) ⇒ Object
Class Method Details
.default_threshold(method) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/visit-counter/visit_counter.rb', line 75 def default_threshold(method) if method.to_sym == :static 10 elsif method.to_sym == :percent 0.3 end end |
.passed_limit?(object, staged_count, diff, name) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/visit-counter/visit_counter.rb', line 58 def passed_limit?(object, staged_count, diff, name) method = object.class.visit_counter_threshold_method || :percent threshold = object.class.visit_counter_threshold || default_threshold(method) if method.to_sym == :static diff >= threshold elsif method.to_sym == :percent return true if staged_count.to_i == 0 diff.to_f / staged_count.to_f >= threshold end end |
.persist(object, staged_count, diff, name) ⇒ Object
70 71 72 73 |
# File 'lib/visit-counter/visit_counter.rb', line 70 def persist(object, staged_count, diff, name) object.update_attribute(name, staged_count + diff) object.nullify_counter_cache(name) end |