Enum_attribute is a project mainly written in Ruby, based on the MIT license.
TODO: one-line summary of your gem
enum_attribute
To install enum_attribute, use the following command:
$ gem install enum_attribute
or write Gemfile and "bundle install"
$ gem 'enum_attribute', :git=>'https://github.com/eijik/enum_attribute.git'
include EnumAttribute
enum_attribute :test, ['a','b','c']
ex.
# class methods will be defined.
Aaa.tests => ['a','b','c']
Aaa.test_names => [ t('activerecord.attributes.aaa.tests.a'),
t('activerecord.attributes.aaa.tests.b'),
t('activerecord.attributes.aaa.tests.c') ]
Aaa.test_name('a') => t('activerecord.attributes.aaa.tests.a')
Aaa.test_pairs => [[t('activerecord.attributes.aaa.tests.a'),a],
[t('activerecord.attributes.aaa.tests.b'),b],
[t('activerecord.attributes.aaa.tests.c'),c]]
# test_pairs method is useful for select_tag
select @aaa, Aaa.test_pairs
# instance methods also will be defined.
@aaa = Aaa.new(:test=>'a')
@aaa.test_name => t('activerecord.attributes.aaa.tests.a')
if true, (name)_pairs method return number in 2nd array and change column name :column => (name)_id automatically! It will be useful for select type ex. seting in a model enum_attribute :test, ['a','b','c'] :number => true you can get object.test_pairs => [[a,1],[b,2],[c,3]]
ex. :column => it will be set when name and column name is difference
if i18n == false ,just return raw data
Copyright (c) 2011 Eiji Kosaki. See LICENSE.txt for further details.