jfcouture / enum_field forked from jamesgolick/enum_field
- Source
- Commits
- Network (9)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
commit 562ca4620444724ce8ec91192467c31d64753d4e
tree e53c1e5e7ee4b076e8c15822154c3264b7a85a72
parent 9f3cbd9095477e2cf1e1a6c934a10a9525bce355
tree e53c1e5e7ee4b076e8c15822154c3264b7a85a72
parent 9f3cbd9095477e2cf1e1a6c934a10a9525bce355
| name | age | message | |
|---|---|---|---|
| |
.gitignore | ||
| |
MIT-LICENSE | ||
| |
README.rdoc | ||
| |
Rakefile | ||
| |
VERSION.yml | ||
| |
enum_field.gemspec | ||
| |
init.rb | ||
| |
lib/ | ||
| |
rails/ | ||
| |
test/ |
README.rdoc
EnumField
Macro to emulate a MySQL enum_field type thing.
Usage
This plugin encapsulates a validates_inclusion_of and automatically gives you a few more goodies automatically. That’s it!
class Computer < ActiveRecord:Base
enum_field :status, ['on', 'off', 'standby', 'sleep', 'out of this world']
# Optionally with a message to replace the default one
# enum_field :status, ['on', 'off', 'standby', 'sleep', 'out of this world'], :message => "incorrect status"
#...
end
This will give you a few things:
- add a validates_inclusion_of with a simple error message ("invalid #{field}") or your custom message
- define the following query methods, in the name of expressive code:
- on?
- off?
- standby?
- sleep?
- out_of_this_world?
- define the STATUSES constant, which contains the acceptable values
License
Copyright © 2008 James Golick, released under the MIT license

