diff options
author | Ronak Jangir <ronakjangir47@gmail.com> | 2015-09-18 21:16:11 +0530 |
---|---|---|
committer | Ronak Jangir <ronakjangir47@gmail.com> | 2015-09-18 21:36:45 +0530 |
commit | 25a9569391f046e7b31a062a88bc1bc8cf4daa22 (patch) | |
tree | f739aecc09e2f9a416e757d58e8d02a60bebb5fd /activerecord | |
parent | b3b9d9ffe59f3038b8c4d9460d0bf41e10d881d8 (diff) | |
download | rails-25a9569391f046e7b31a062a88bc1bc8cf4daa22.tar.gz rails-25a9569391f046e7b31a062a88bc1bc8cf4daa22.tar.bz2 rails-25a9569391f046e7b31a062a88bc1bc8cf4daa22.zip |
DRY enum conflict detection
Diffstat (limited to 'activerecord')
-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 |