diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2015-09-18 09:50:58 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2015-09-18 09:50:58 -0700 |
commit | 76c7162c1d63dc8a7a324913f0a7ba9d3f9165ec (patch) | |
tree | 9da6aa3245e25d96e0d65291679f112e0f2313ea /activerecord/lib | |
parent | 4fac20688b190da9da741e4a6d65d2adfab40772 (diff) | |
parent | 25a9569391f046e7b31a062a88bc1bc8cf4daa22 (diff) | |
download | rails-76c7162c1d63dc8a7a324913f0a7ba9d3f9165ec.tar.gz rails-76c7162c1d63dc8a7a324913f0a7ba9d3f9165ec.tar.bz2 rails-76c7162c1d63dc8a7a324913f0a7ba9d3f9165ec.zip |
Merge pull request #21666 from ronakjangir47/enum_refactoring
DRY enum conflict detection
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 4902fcb1a2..a79bf0366b 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -204,30 +204,22 @@ module ActiveRecord def detect_enum_conflict!(enum_name, method_name, klass_method = false) if klass_method && dangerous_class_method?(method_name) - raise ArgumentError, ENUM_CONFLICT_MESSAGE % { - enum: enum_name, - klass: self.name, - type: 'class', - method: method_name, - source: 'Active Record' - } + raise_conflict_error(enum_name, method_name, type: 'class') elsif !klass_method && dangerous_attribute_method?(method_name) - raise ArgumentError, ENUM_CONFLICT_MESSAGE % { - enum: enum_name, - klass: self.name, - type: 'instance', - method: method_name, - source: 'Active Record' - } + raise_conflict_error(enum_name, method_name) elsif !klass_method && method_defined_within?(method_name, _enum_methods_module, Module) - raise ArgumentError, ENUM_CONFLICT_MESSAGE % { - enum: enum_name, - klass: self.name, - type: 'instance', - method: method_name, - source: 'another enum' - } + raise_conflict_error(enum_name, method_name, source: 'another enum') end end + + def raise_conflict_error(enum_name, method_name, type: 'instance', source: 'Active Record') + raise ArgumentError, ENUM_CONFLICT_MESSAGE % { + enum: enum_name, + klass: self.name, + type: type, + method: method_name, + source: source + } + end end end |