[openstreetmap/openstreetmap-website] Refactoring visible = true / acts_as_paranoid (#1287)
notifications at github.com
Wed Sep 14 14:29:18 UTC 2016
There's lots of places around our (non-API) codebase that includes visible boolean flags on the models (for example, DiaryEntry and DiaryComment models). I'd like to refactor so that, rather than having to ensure that `.visible?` is correctly called all over the place, to default to showing only visible objects and doing something special when needing to see the hidden ones. So DiaryEntry.all should only return visible entries by default. DiaryEntry.something_rare.all would return the hidden entries for those rare occasions (e.g. moderation) where the hidden ones are shown.
This immediately makes me think of the [acts_as_paranoid](https://github.com/ActsAsParanoid/acts_as_paranoid) gem, which is widely used for soft-deleting objects. Unfortunately while acts_as_paranoid has support for boolean "deleted" columns, it doesn't have support for the inverse i.e. a "visible" column.
I don't want to end up accidentally re-implementing that entire gem by creating bunches of scopes!
Does anyone have any suggestions? Should we just rename the "visible" column to "deleted" (and invert the contents, obviously) so that we can use the gem directly? Or something else?
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rails-dev