Sha256: 76c6bc9eef876af7a6ba3e5336c91f53eed7f79f8c2f23c3b61b0b5bc7da02ea
Contents?: true
Size: 1.36 KB
Versions: 4
Compression:
Stored size: 1.36 KB
Contents
# BetterEnum Sligtly extension of builtin enum. ## Usage ### Enum definication The examples below is to be under following model with enum. ```ruby class Employee < ApplicationRecord enum gender: {male: 0, female: 1, other: 2} end ``` ### Translation definication Define translation definication under activerecord > enums as follows: ```yaml en: activerecord: enums: employee: gender: male: 'Male' female: 'Female' other: 'Other' ``` ### Singleton methods You can get specified translated label and specified value, and also get set of key and translated label pairs. ```ruby Employee.gender_label(:male) # => "Male" Employee.gender_value(:female) # => 1 Employee.gender_labels # => {"male" => "Male", "female" => "Female", "other" => "Other"} ``` ### Instance methods You can get translated label and value. ```ruby female_employee.gender_label # => "Female" other_employee.gender_value # => 2 ``` ## Installation Add this line to your application's Gemfile: ```ruby gem 'better_enum' ``` And then execute: ```bash $ bundle ``` Or install it yourself as: ```bash $ gem install better_enum ``` ## Contributing Bug reports and pull requests are accepted on GitHub at https://github.com/smoriwaki/better_enum. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
better_enum-1.1.0 | README.md |
better_enum-1.0.2 | README.md |
better_enum-1.0.1 | README.md |
better_enum-1.0.0 | README.md |