0.0
No release in over a year
A tiny gem that extends Rails enums to allow human-friendly labels
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 13.2, >= 13.2.1
~> 3.13
 Project Readme


What's PrettyEnum?

A tiny gem that extends Rails enums to allow human-friendly labels.

If you’re wondering why not just use a string column for storing enumerated values—the answer is, you can. However, doing so can slow down database queries. The better approach is to store enums as integers for optimal performance while still displaying human-readable values effortlessly with PrettyEnum.

Getting Started

  1. Install gem

      gem 'pretty_enum'
    
      bundle install
  2. Add PrettyEnum to your class and define pretty_enum method

    class Base < ActiveRecord::Base
      extend PrettyEnum
    
      enum :status, invitation_pending: 0, accepted: 1, deactivated: 2
      pretty_enum :statuses
    end
  3. It supported Hash and Array syntax

    enum :status, invitation_pending: 0, accepted: 1, deactivated: 2
    enum :status, [ :invitation_pending, :accepted, :deactivated ]
  4. Use generated pretty_{enum_name} method

      Base.pretty_statuses
      => { invitation_pending: 'Invitation Pending',
           accepted:           'Accepted',
           deactivated:        'Deactivated'
         }