EnumFromFile
If you've ever found yourself in a situation where you feel like you should use enum, but it has 50 potions so you don't know where to put it, the answer is here!
Just store your enums in a .yml file!
This makes little sense when you have a small enum with just a couple of options, but the more options you have, the easier it is to see the benefits of using it.
Usage
- Create a folder
/config/enumsto store your enum files in .yml format. - Add
include EnumFromFileto theApplicationRecordor your target model. - Make sure your enum column has a type
string.
Et voila!
Given a file /config/enums/eye_colors.yml you add eye_color enum to a Cat model with the following line:
enum :eye_color, from_file: :eye_colors
You can continue using regular syntax for regular cases:
enum status: { active: active, archived: archived }
All the options will be passed to native enum implementation as expected.
Installation
Add this line to your application's Gemfile:
gem 'enum_from_file'
And then execute:
$ bundle
Or install it yourself as:
$ gem install enum_from_file
Contributing
Bug reports and pull requests are welcome on project's page at GitHub
License
The gem is available as open source under the terms of the MIT License.