Module: Counter::Recalculatable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Value
- Defined in:
- app/models/concerns/counter/recalculatable.rb
Instance Method Summary collapse
- #count_by_sql ⇒ Object
-
#recalc! ⇒ Object
Support for regenerating the counters.
-
#recalc_scope ⇒ Object
use this scope when recalculating the value.
- #sum_by_sql ⇒ Object
Instance Method Details
#count_by_sql ⇒ Object
12 13 14 |
# File 'app/models/concerns/counter/recalculatable.rb', line 12 def count_by_sql recalc_scope.count end |
#recalc! ⇒ Object
Support for regenerating the counters
5 6 7 8 9 10 |
# File 'app/models/concerns/counter/recalculatable.rb', line 5 def recalc! with_lock do new_value = definition.sum? ? sum_by_sql : count_by_sql update! value: new_value end end |
#recalc_scope ⇒ Object
use this scope when recalculating the value
21 22 23 |
# File 'app/models/concerns/counter/recalculatable.rb', line 21 def recalc_scope parent.association(definition.association_name).scope end |
#sum_by_sql ⇒ Object
16 17 18 |
# File 'app/models/concerns/counter/recalculatable.rb', line 16 def sum_by_sql recalc_scope.sum(definition.column_to_count) end |