This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Mon Feb 09 16:51:41 -0800 2009 | |
| |
MIT-LICENSE | Mon Jan 21 09:56:43 -0800 2008 | |
| |
README.rdoc | Tue Feb 10 12:26:55 -0800 2009 | |
| |
Rakefile | Tue Feb 10 10:40:49 -0800 2009 | |
| |
VERSION.yml | Tue Apr 07 09:46:43 -0700 2009 | |
| |
enum_field.gemspec | Tue Apr 07 09:47:03 -0700 2009 | |
| |
init.rb | Mon Jan 21 10:00:37 -0800 2008 | |
| |
lib/ | Tue Apr 07 12:02:38 -0700 2009 | |
| |
rails/ | Tue Feb 10 14:39:55 -0800 2009 | |
| |
test/ | Tue Apr 07 12:02:38 -0700 2009 |
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







