podia/counter

Rethink the singleton approach?

ideasasylum opened this issue · 0 comments

I'm not entirely happy with the singleton definition (threadsafe?) or some of the meta-programming in definition. Seems like someone with more experience could refactor this in a "Rails way".

The singleton definitions are useful because we can initialize them once and attach them to any instance of the counter values. This separation of the counter definition and Counter::Value has some advantages, and will particularly be useful when there is a choice of how values are stored (e.g. Counter::Value, Counter::HLL, Counter::Slotted, Counter::…). The definition is just there to store information about the association, models involved, conditions, hooks, etc.

I don't think I see singletons used like this very often so I'm curious what the alternative might be for storing these global, immutable definitions.