Skip to content

Commit 0bf4f87

Browse files
Merge pull request rails#46584 from sampatbadhe/improve-enum-docs
Improve enum docs for instance_methods and scopes [ci-skip]
2 parents 90fc21f + 9ffbb92 commit 0bf4f87

File tree

1 file changed

+5
-3
lines changed
  • activerecord/lib/active_record

1 file changed

+5
-3
lines changed

activerecord/lib/active_record/enum.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ module ActiveRecord
115115
# If you want to disable the auto-generated methods on the model, you can do
116116
# so by setting the +:instance_methods+ option to false:
117117
#
118-
# enum :status, [ :active, :archived ], instance_methods: false
118+
# class Conversation < ActiveRecord::Base
119+
# enum :status, [ :active, :archived ], instance_methods: false
120+
# end
119121
module Enum
120122
def self.extended(base) # :nodoc:
121123
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
261263
define_method("#{value_method_name}!") { update!(name => value) }
262264
end
263265

264-
# scope :active, -> { where(status: 0) }
265-
# scope :not_active, -> { where.not(status: 0) }
266266
if scopes
267+
# scope :active, -> { where(status: 0) }
267268
klass.send(:detect_enum_conflict!, name, value_method_name, true)
268269
klass.scope value_method_name, -> { where(name => value) }
269270

271+
# scope :not_active, -> { where.not(status: 0) }
270272
klass.send(:detect_enum_conflict!, name, "not_#{value_method_name}", true)
271273
klass.scope "not_#{value_method_name}", -> { where.not(name => value) }
272274
end

0 commit comments

Comments
 (0)