No commit activity in last 3 years
No release in over 3 years
ActiveRecord::EnumWithLabel adds label and more to ActiveRecord::Base.enum.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.12
>= 0
~> 10.0
~> 3.0

Runtime

 Project Readme

ActiveRecord::EnumWithLabel

ActiveRecord::EnumWithLabel adds label and more to ActiveRecord.enum.

Installation

Add this line to your application's Gemfile:

gem 'active_record-enum_with_label'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_record-enum_with_label

Usage

class User < ActiveRecord::Base
  include ActiveRecord::EnumWithLabel

  enum_with_label :alert_status, {
    alert_status_none: 'なし',
    alert_status_mail_sent: 'メール送信',
    alert_status_telephoned: '電話',
  }
end

User.alert_status_labels # => ['なし', 'メール送信', '電話']
user = User.create(alert_status: :alert_status_none)
user.alert_status_label            # => 'なし'
user.alert_status_before_type_cast # => 0
class Issue < ActiveRecord::Base
  include ActiveRecord::EnumWithLabel

  enum_with_label :status, {
    status_bug: {
      label: '不具合', value: 5, icon: :fire
    },
    status_feature: {
      label: '新機能', value: 10, icon: '+1'
    },
    status_question: {
      label: '質問', value: 15, icon: 'question_mark'
    },
  }
end

issue = Issue.create!(status: :status_bug)
issue.status_label            # => '不具合'
issue.status_icon             # => :fire
issue.status_before_type_cast # => 5

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jiikko/active_record-enum_with_label.