brainspec / enumerize

Enumerated attributes with I18n and ActiveRecord/Mongoid support
MIT License
1.72k stars 190 forks source link

Support enumerization of the same attribute in child class. #448

Closed nashby closed 4 months ago

nashby commented 4 months ago

Typical use case of this is:

class User < ActiveRecord::Base
  enumerize :role, in: [:user]
end

class Admin < User
  enumerize :role, in: [:user, :admin]
end

So if we want to redefine enumerized field in a child class we call enumerize again and that's causes issue since we try to decorate this role field again and when we try to cast given value we end up with calling cast on enumerized Type object but for already decorated attribute we just want to return its plain value, not a casted one.