Method: ClassyEnum::ClassMethods#enum_classes

Defined in:
lib/classy_enum/class_methods.rb

#enum_classes(*enums) ⇒ Object

Macro for defining enum members within a ClassyEnum class. Accepts an array of symbols or strings which are converted to ClassyEnum members as descents of their parent class.

Example

# Define an enum called Priority with three child classes
class Priority < ClassyEnum::Base
  enum_classes :low, :medium, :high
end

The child classes will be defined with the following constants:
PriorityLow, PriorityMedium, and PriorityHigh

These child classes can be instantiated with either:
Priority.build(:low) or PriorityLow.new


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/classy_enum/class_methods.rb', line 20

def enum_classes(*enums)
  ActiveSupport::Deprecation.warn('enum_classes is deprecated, and will be removed in ClassyEnum 3.0. It is no longer needed.', caller)

  self.class_eval do
    class_attribute :enum_options, :base_class

    self.enum_options = enums.map(&:to_sym)
    self.base_class = self

    # # Use ActiveModel::AttributeMethods to define attribute? methods
    attribute_method_suffix '?'
    define_attribute_methods enums
  end
end