Module: Counter::Verifyable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Value
- Defined in:
- app/models/concerns/counter/verifyable.rb
Instance Method Summary collapse
- #correct! ⇒ Object
- #correct? ⇒ Boolean
-
#verify ⇒ Object
Returns [correct_value, current_value]: the value recomputed from live data, and the value currently stored on the counter.
Instance Method Details
#correct! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/concerns/counter/verifyable.rb', line 13 def correct! # We can't verify these values: manual counters (which includes globals) # have no countable source of truth, so their stored value is authoritative. return true if definition.manual? correct_value, current_value = verify requires_recalculation = correct_value != current_value update! value: correct_value if requires_recalculation !requires_recalculation end |
#correct? ⇒ Boolean
4 5 6 7 8 9 10 11 |
# File 'app/models/concerns/counter/verifyable.rb', line 4 def correct? # We can't verify these values: manual counters (which includes globals) # have no countable source of truth, so their stored value is authoritative. return true if definition.manual? correct_value, current_value = verify correct_value == current_value end |
#verify ⇒ Object
Returns [correct_value, current_value]: the value recomputed from live data, and the value currently stored on the counter.
28 29 30 31 32 33 34 |
# File 'app/models/concerns/counter/verifyable.rb', line 28 def verify if definition.calculated? [calculate, value] else [count_by_sql, value] end end |