0.0
The project is in a healthy, maintained state
Stop using integers in your database when using enums. Use the enum type define in your model for better DX.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 7.1.3.2
 Project Readme

LiteralEnum

Stop using integers in your database when using enums. Use the enum type define in your model for better DX.

Usage

The following class_method is added to your arsenal and now ["pending", "accepted"] are saved as strings in your database.

class Article < ApplicationRecord
  # @NOTE:
  # The column `status` is supposed to be of type string in your database.
  literal_enum :status, ["pending", "accepted"]
end

Installation

Add this line to your application's Gemfile:

gem "literal_enum"

And then execute:

$ bundle

Or install it yourself as:

$ gem install literal_enum

Contributing

Open a PR ;)

License

The gem is available as open source under the terms of the MIT License.

Special thanks:

Huge shout-out to hundredwatt!

I was tired of this integer in the database when using enums, and he jumped into the discussion on Twitter and showed me this:

After learning about Rails engines, I thought that this could be a great first gem ;)

The original class_method is actually from the gist by @hundredwatt.