[openstreetmap/openstreetmap-website] Refactoring visible = true / acts_as_paranoid (#1287)

Andy Allan 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:
https://github.com/openstreetmap/openstreetmap-website/issues/1287
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20160914/b0d44cb8/attachment.html>


More information about the rails-dev mailing list