-
Notifications
You must be signed in to change notification settings - Fork 61
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 theREADME.md
for the support options. - Getting the "raw" enum value requires now to type
User.genders[:male]
instead ofUser.male
. -
User.genders
returns aSimpleEnum::Enum
instead ofSimpleEnum::EnumHash
. - ActiveRecord/Mongoid only: Added
User.females
which returns a relation similar towhere(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 outSimpleEnum::ViewHelpers
which provides aenum_option_pairs
method. - The
as_enum: true
validation is no longer used.