active_enum icon indicating copy to clipboard operation
active_enum copied to clipboard

Adding the ability to write enums as strings.

Open briespoke opened this issue 9 years ago • 1 comments

Firstly, thank you for writing this module. It has improved the performance of my employer's application greatly.

We generally expect that a setter can accept a value from its own getter. However, when using ActiveEnum.use_name_as_value = true, enums must be written as either symbols or integers. Consider the following situation:

person = Person.new(sex: :male)
puts person.sex # "Male"
person.sex = person.sex
puts person.sex # nil

This behavior is counter-intuitive: a leaky abstraction. Particularly, it causes issues saving form data. This commit makes an enum accept strings, symbols and integers, fixing the leaky abstraction.

Take care and thank you for reviewing this request.

briespoke avatar Oct 11 '14 01:10 briespoke

In principal I can see this would make things more consistent. The problem is it interferes with normal typecasting of strings to integers which can be passed to a write method in various scenarios. The result could be a nil when assigning a '1' for example. Not what we want.

adzap avatar Oct 09 '16 00:10 adzap