Skip to content

1.x to 2.x Migration Guide

Joshua Pinter edited this page Dec 16, 2018 · 3 revisions

Version 2.x is a rewrite to ensure a more modular and even less obtrusive variant of support enum fields in ActiveRecord or other ruby objects. Due to this it is backwards incompatible with 1.x. This page highlights the changes between 1.x and 2.x and should help with the migration. If anything important is missing, feel free to add, thx.

  • The as_enum method now accepts different and less options, see the README.md for the support options.
  • Getting the "raw" enum value requires now to type User.genders[:male] instead of User.male.
  • User.genders returns a SimpleEnum::Enum instead of SimpleEnum::EnumHash.
  • ActiveRecord/Mongoid only: Added User.females which returns a relation similar to where(gender_cd: self.class.genders[:female]).
  • Instance level methods still exist, i.e. gender=, gender, gender?(x), male?, female?, male!, female! and the dirty methods.
  • The only remaining translation methods is User.human_enum_name(enum, key), to build select options also check out SimpleEnum::ViewHelpers which provides a enum_option_pairs method.
  • The as_enum: true validation is no longer used.
Clone this wiki locally