How do I test if an ActiveRecord attribute is an Enum?
ActiveRecord::Enum
adds a defined_enums
class attribute to the model - a hash storing the defined enums:
MyModel.defined_enums
#=> {"status"=>{"in_progress"=>0, "accepted"=>1, "approved"=>2, "declined"=>3, "closed"=>4, "cancelled"=>5, "submitted"=>6}}
To test if an attribute is an enum you could use:
MyModel.defined_enums.has_key?('status')
#=> true
Unfortunately, defined_enums
is not documented.