Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

literal_enum

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

literal_enum

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 15 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc