How to use enumerations in ActiveRecord and non-ActiveRecord classes
mainEnumerateIt can be used in any Ruby class.
For ActiveRecord models, use the has_enumeration_for macro directly.
For non-ActiveRecord classes, you must extend EnumerateIt and provide an attr_accessor for the attribute before calling has_enumeration_for.
If the enumeration class name is different from the attribute name, use the with: option to specify the class.
# ActiveRecord instance
class Person < ApplicationRecord
has_enumeration_for :relationship_status
end
# Non-ActiveRecord instance
class Person
extend EnumerateIt
attr_accessor :relationship_status
has_enumeration_for :relationship_status
end
# Using a specific enumeration class
class Person < ApplicationRecord
has_enumeration_for :relationship_status, with: RelationshipStatus
end