aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorEdu Depetris <edu.depetris.00@gmail.com>2019-06-02 18:01:01 -0300
committerEdu Depetris <edu.depetris.00@gmail.com>2019-06-30 15:21:30 -0300
commit77daacf94d7d26c713d4412b68edb64260fc22d9 (patch)
treed3090360c32b705673ce8cff77d62163a0d669ae /activerecord/lib
parent4b621df3840542c369a2db40529396033af3ec55 (diff)
downloadrails-77daacf94d7d26c713d4412b68edb64260fc22d9.tar.gz
rails-77daacf94d7d26c713d4412b68edb64260fc22d9.tar.bz2
rails-77daacf94d7d26c713d4412b68edb64260fc22d9.zip
Add a warning for enum elements with 'not_' prefix.
When a enum element contains the prefix 'not_'. I warns to users to be aware of this new feature. Example code: class Foo < ActiveRecord::Base enum status: [:sent, :not_sent] end
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/enum.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb
index 8077630aeb..fc49f752aa 100644
--- a/activerecord/lib/active_record/enum.rb
+++ b/activerecord/lib/active_record/enum.rb
@@ -200,6 +200,8 @@ module ActiveRecord
# scope :active, -> { where(status: 0) }
# scope :not_active, -> { where.not(status: 0) }
if enum_scopes != false
+ klass.send(:detect_negative_condition!, value_method_name)
+
klass.send(:detect_enum_conflict!, name, value_method_name, true)
klass.scope value_method_name, -> { where(attr => value) }
@@ -261,5 +263,12 @@ module ActiveRecord
source: source
}
end
+
+ def detect_negative_condition!(method_name)
+ if method_name.start_with?("not_") && logger
+ logger.warn "An enum element in #{self.name} uses the prefix 'not_'." \
+ " This will cause a conflict with auto generated negative scopes."
+ end
+ end
end
end