@@ -115,7 +115,9 @@ module ActiveRecord
115
115
# If you want to disable the auto-generated methods on the model, you can do
116
116
# so by setting the +:instance_methods+ option to false:
117
117
#
118
- # enum :status, [ :active, :archived ], instance_methods: false
118
+ # class Conversation < ActiveRecord::Base
119
+ # enum :status, [ :active, :archived ], instance_methods: false
120
+ # end
119
121
module Enum
120
122
def self . extended ( base ) # :nodoc:
121
123
base . class_attribute ( :defined_enums , instance_writer : false , default : { } )
@@ -261,12 +263,12 @@ def define_enum_methods(name, value_method_name, value, scopes, instance_methods
261
263
define_method ( "#{ value_method_name } !" ) { update! ( name => value ) }
262
264
end
263
265
264
- # scope :active, -> { where(status: 0) }
265
- # scope :not_active, -> { where.not(status: 0) }
266
266
if scopes
267
+ # scope :active, -> { where(status: 0) }
267
268
klass . send ( :detect_enum_conflict! , name , value_method_name , true )
268
269
klass . scope value_method_name , -> { where ( name => value ) }
269
270
271
+ # scope :not_active, -> { where.not(status: 0) }
270
272
klass . send ( :detect_enum_conflict! , name , "not_#{ value_method_name } " , true )
271
273
klass . scope "not_#{ value_method_name } " , -> { where . not ( name => value ) }
272
274
end
0 commit comments