xing/flag_shih_tzu — pull request #16 by GoldsteinTechPartners (2012-02-06 18:32:20+00:00)
Title: Allow multiple requires/reloads of classes which include FlagShihTzu

Reloads of my User class, which includes FlagShihTzu, were failing on an error in has_flags. Specifically I was getting:

has_flags: flag name can_assign_permissions already defined, please choose different name

This reload was forced by certain client tasks (e.g. Sunspot's reindex task), and isn't something I can control without patching those tasks.

The ultimate cause of this issue was that including the FlagShihTzu library overwrites the flag_mapping and flag_options class attributes, wiping them clean. So FlagShihTzu attempts to redefine all of its flags and runs into a method conflict.

Attached is a simple patch that only define the flag_mapping and flag_options variables if they aren't already defined. This makes the code resilient against reload.