0.0
No commit activity in last 3 years
No release in over 3 years
JTRailsEnum let you use enum in your models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

JTRailsEnum

Gem Version

JTRailsEnum let you use enum in your models. JTRailsEnum doesn't works exactly like enum in Ruby On Rails. It always add a prefix, which is a better behavior when you use multiple enums in a model. The prefix option is also not present in the Ruby On Rails 4.0.

Installation

JTRailsEnum is distributed as a gem, which is how it should be used in your app.

Include the gem in your Gemfile:

gem 'jt-rails-enum', '~> 1.0'

Usage

Basic usage

class User < ActiveRecord::Base

    jt_enum confirmation_status: [
        :waiting,
        :accepted,
        :refused
    ]

end

Scopes and some basic methods are automatically created for each value in the enum.

# User.where(confirmation_status: User.confirmation_statuses[:waiting]).first
user = User.confirmation_status_waiting.first

# User.where.not(confirmation_status: User.confirmation_statuses[:waiting]).first
user = User.confirmation_status_not_waiting.first

# Equivalent to user.update!(confirmation_status: User.confirmation_statuses[:accepted])
user.confirmation_status_accepted!

# Equivalent to user.confirmation_status == User.confirmation_statuses[:accepted]
user.confirmation_status_accepted?

Author

License

JTRailsEnum is released under the MIT license. See the LICENSE file for more info.