-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
37 lines (25 loc) · 922 Bytes
/
README
File metadata and controls
37 lines (25 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
== AttrEnum
AttrEnum enables you to define ActiveRecord attributes like enums with specific values, names, and symbols
== Example
Assume user has a integer column status
class User < ActiveRecord::Base
attr_enum :status, {
:active => 1,
:was_suspended => 2,
:cancelled => 3,
:deleted => {:id => 4, :name => 'Deleted User'}
}
validates_inclusion_of :status, :in => Status.values
end
Now you can do:
user.status = User::Status::Deleted
user.status_deleted? == true
user.status_name == 'Deleted User'
and ...
user.status = User::Status::Active
user.status_active? == true
user.status_deleted? == false
user.status_name == 'Deleted'
You can also get at an options list for forms:
User::Status.options = [['Active', '1'], ['Was Suspended', '2'], ['Cancelled', '3'], ['Deleted User','4']]
Copyright (c) 2009 Kris Rasmussen, released under the MIT license