@@ -119,7 +119,18 @@ module ActiveRecord
119
119
# enum :status, [ :active, :archived ], instance_methods: false
120
120
# end
121
121
#
122
- # If you want the enum value to be validated before saving, use the option +:validate+:
122
+ # By default, an +ArgumentError+ will be raised when assigning an invalid value:
123
+ #
124
+ # class Conversation < ActiveRecord::Base
125
+ # enum :status, [ :active, :archived ]
126
+ # end
127
+ #
128
+ # conversation = Conversation.new
129
+ #
130
+ # conversation.status = :unknown # 'unknown' is not a valid status (ArgumentError)
131
+ #
132
+ # If, instead, you want the enum value to be validated before saving, use the
133
+ # +:validate+ option:
123
134
#
124
135
# class Conversation < ActiveRecord::Base
125
136
# enum :status, [ :active, :archived ], validate: true
@@ -136,7 +147,7 @@ module ActiveRecord
136
147
# conversation.status = :active
137
148
# conversation.valid? # => true
138
149
#
139
- # It is also possible to pass additional validation options:
150
+ # You may also pass additional validation options:
140
151
#
141
152
# class Conversation < ActiveRecord::Base
142
153
# enum :status, [ :active, :archived ], validate: { allow_nil: true }
@@ -152,16 +163,6 @@ module ActiveRecord
152
163
#
153
164
# conversation.status = :active
154
165
# conversation.valid? # => true
155
- #
156
- # Otherwise +ArgumentError+ will raise:
157
- #
158
- # class Conversation < ActiveRecord::Base
159
- # enum :status, [ :active, :archived ]
160
- # end
161
- #
162
- # conversation = Conversation.new
163
- #
164
- # conversation.status = :unknown # 'unknown' is not a valid status (ArgumentError)
165
166
module Enum
166
167
def self . extended ( base ) # :nodoc:
167
168
base . class_attribute ( :defined_enums , instance_writer : false , default : { } )
0 commit comments