Set ActiveRecord::Enum from a string

I’ve been trying out the ActiveRecord::Enum that was added in Rails 4.1.

One question I have is about an existing Rails app with a status code that’s set by a external project using an API. This means setting the status from a string pulled out of some JSON.

In other words, what if setting the enum is not something as tidy or controlled as a form dropdown select but an unknown string.

A couple model methods seem to take care of two of the main concerns.

Check if string is a valid enum value?

Set the enum value and return true or false

The second method could be move out somewhere and made DRY. In fact I’m a little surprised something like this isn’t already part of ActiveRecord::Enum …