power_enum 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -5
- data/lib/active_record/acts/enumerated.rb +5 -0
- metadata +104 -77
data/README.md
CHANGED
@@ -111,7 +111,8 @@ You can now customize it.
|
|
111
111
|
# t.string :name, :limit => 50, :null => false
|
112
112
|
# end
|
113
113
|
|
114
|
-
Now, when you create your Booking model, your migration should create a reference column for status id's and a foreign
|
114
|
+
Now, when you create your Booking model, your migration should create a reference column for status id's and a foreign
|
115
|
+
key relationship to the booking\_statuses table.
|
115
116
|
|
116
117
|
create_table :bookings do |t|
|
117
118
|
t.integer :status_id
|
@@ -121,6 +122,14 @@ Now, when you create your Booking model, your migration should create a referenc
|
|
121
122
|
|
122
123
|
# Ideally, you would use a gem of some sort to handle foreign keys.
|
123
124
|
execute "ALTER TABLE bookings ADD 'bookings_bookings_status_id_fk' FOREIGN KEY (status_id) REFERENCES booking_statuses (id);"
|
125
|
+
|
126
|
+
It's easier to use the `references` method if you intend to stick to the default naming convention for reference columns.
|
127
|
+
|
128
|
+
create_table :bookings do |t|
|
129
|
+
t.references :booking_status # Same as t.integer booking_status_id
|
130
|
+
|
131
|
+
t.timestamps
|
132
|
+
end
|
124
133
|
|
125
134
|
There are two methods added to Rails migrations:
|
126
135
|
|
@@ -128,10 +137,10 @@ There are two methods added to Rails migrations:
|
|
128
137
|
|
129
138
|
Creates a new enum table. `enum_name` will be automatically pluralized. The following options are supported:
|
130
139
|
|
131
|
-
- [:
|
140
|
+
- [:name\_column] Specify the column name for name of the enum. By default it's :name. This can be a String or a Symbol
|
132
141
|
- [:description] Set this to `true` to have a 'description' column generated.
|
133
|
-
- [:
|
134
|
-
- [:
|
142
|
+
- [:name\_limit] Set this define the limit of the name column.
|
143
|
+
- [:desc\_limit] Set this to define the limit of the description column
|
135
144
|
- [:active] Set this to `true` to have a boolean 'active' column generated. The 'active' column will have the options of NOT NULL and DEFAULT TRUE.
|
136
145
|
- [:timestamps] Set this to `true` to have the timestamp columns (created\_at and updated\_at) generated
|
137
146
|
|
@@ -289,7 +298,8 @@ This method is used by the `inactive` class method to select inactive enums.
|
|
289
298
|
#### Notes
|
290
299
|
|
291
300
|
`acts_as_enumerated` records are considered immutable. By default you cannot create/alter/destroy instances because they are cached in memory.
|
292
|
-
Because of Rails' process-based model it is not safe to allow updating acts\_as\_enumerated records as the caches will get out of sync.
|
301
|
+
Because of Rails' process-based model it is not safe to allow updating acts\_as\_enumerated records as the caches will get out of sync. Also,
|
302
|
+
as of version 0.5.1, `to_s` is overriden to return the name of the enum instance.
|
293
303
|
|
294
304
|
However, one instance where updating the models *should* be allowed is if you are using seeds.rb to seed initial values into the database.
|
295
305
|
|
@@ -236,6 +236,11 @@ module ActiveRecord
|
|
236
236
|
self.name.to_sym
|
237
237
|
end
|
238
238
|
|
239
|
+
# By default enumeration #to_s should return stringified name of the enum. BookingStatus[:foo].to_s returns "foo"
|
240
|
+
def to_s
|
241
|
+
self.name.to_s
|
242
|
+
end
|
243
|
+
|
239
244
|
# Returns true if the instance is active, false otherwise. If it has an attribute 'active',
|
240
245
|
# returns the attribute cast to a boolean, otherwise returns true. This method is used by the 'active'
|
241
246
|
# class method to select active enums.
|
metadata
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_enum
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Trevor Squires
|
9
14
|
- Pivotal Labs
|
10
15
|
- Arthur Shagall
|
@@ -12,82 +17,98 @@ authors:
|
|
12
17
|
autorequire:
|
13
18
|
bindir: bin
|
14
19
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
|
21
|
+
date: 2011-12-02 00:00:00 Z
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
20
25
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
24
34
|
version: 3.0.0
|
25
|
-
|
35
|
+
name: rails
|
26
36
|
prerelease: false
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
type: :runtime
|
38
|
+
requirement: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
31
41
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
|
36
|
-
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
name: jeweler
|
37
50
|
prerelease: false
|
38
|
-
version_requirements: *10817360
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: rspec
|
41
|
-
requirement: &10816140 !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ! '>='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
51
|
type: :development
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
name: sqlite3
|
52
|
-
requirement: &10813220 !ruby/object:Gem::Requirement
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
55
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
name: rspec
|
64
|
+
prerelease: false
|
58
65
|
type: :development
|
66
|
+
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
name: sqlite3
|
59
78
|
prerelease: false
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
79
|
+
type: :development
|
80
|
+
requirement: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
64
83
|
none: false
|
65
|
-
requirements:
|
66
|
-
- - =
|
67
|
-
- !ruby/object:Gem::Version
|
84
|
+
requirements:
|
85
|
+
- - "="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 21
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
- 2
|
91
|
+
- 1
|
68
92
|
version: 0.2.1
|
69
|
-
|
93
|
+
name: genspec
|
70
94
|
prerelease: false
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
It allows you to cleanly solve many of the problems that the traditional Rails alternatives
|
76
|
-
|
77
|
-
|
78
|
-
It is particularly suitable for scenarios where your Rails application is not the
|
79
|
-
only user of the database, such as
|
80
|
-
|
81
|
-
when it''s used for analytics or reporting.
|
95
|
+
type: :development
|
96
|
+
requirement: *id005
|
97
|
+
description: |
|
98
|
+
Power Enum allows you to treat instances of your ActiveRecord models as though they were an enumeration of values.
|
99
|
+
It allows you to cleanly solve many of the problems that the traditional Rails alternatives handle poorly if at all.
|
100
|
+
It is particularly suitable for scenarios where your Rails application is not the only user of the database, such as
|
101
|
+
when it's used for analytics or reporting.
|
82
102
|
|
83
|
-
'
|
84
103
|
email: arthur.shagall@gmail.com
|
85
104
|
executables: []
|
105
|
+
|
86
106
|
extensions: []
|
87
|
-
|
107
|
+
|
108
|
+
extra_rdoc_files:
|
88
109
|
- LICENSE
|
89
110
|
- README.md
|
90
|
-
files:
|
111
|
+
files:
|
91
112
|
- examples/virtual_enumerations_sample.rb
|
92
113
|
- lib/active_record/acts/enumerated.rb
|
93
114
|
- lib/active_record/aggregations/has_enumerated.rb
|
@@ -105,30 +126,36 @@ files:
|
|
105
126
|
- README.md
|
106
127
|
homepage: http://github.com/albertosaurus/enumerations_mixin
|
107
128
|
licenses: []
|
129
|
+
|
108
130
|
post_install_message:
|
109
131
|
rdoc_options: []
|
110
|
-
|
132
|
+
|
133
|
+
require_paths:
|
111
134
|
- lib
|
112
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
136
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
-
segments:
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
119
142
|
- 0
|
120
|
-
|
121
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
145
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
127
153
|
requirements: []
|
154
|
+
|
128
155
|
rubyforge_project:
|
129
156
|
rubygems_version: 1.8.10
|
130
157
|
signing_key:
|
131
158
|
specification_version: 3
|
132
|
-
summary: Allows you to treat instances of your ActiveRecord models as though they
|
133
|
-
were an enumeration of values
|
159
|
+
summary: Allows you to treat instances of your ActiveRecord models as though they were an enumeration of values
|
134
160
|
test_files: []
|
161
|
+
|