[Enum enhancement proposal]: handle "sole" options

The purpose of the enhancement is to allow the .enum class_method to have a sole option. Defining a sole leads to modify scopes and instance_methods.

It could be done like that:

enum :role, [:base, :default, :fallback, :lower_cost], sole: { except: :base }

The sole option:

  • is false by default
  • can accept a boolean → leads to modify all scopes and instance_methods
  • can accept a hash with only and except keys which themselves accept a value or an array of values → leads to modify all scopes and instance_methods for/excluding the value(s) of the sole hash value

Then in ActiveRecord::Enum there will be define_sole_enum_methods:

  • scopes that use the .find_sole_by
  • #value! instance_method that first update the old sole object and assign the new sole object to self
  • #value? instance_method that verify if the object (self) is the sole one

And in _enum class_method use define_enum_methods or define_sole_enum_methods depending of the sole option for each values.