File tree Expand file tree Collapse file tree 3 files changed +4
-10
lines changed
grape/validations/validators Expand file tree Collapse file tree 3 files changed +4
-10
lines changed Original file line number Diff line number Diff line change 44
55* [ #2326 ] ( https://github.com/ruby-grape/grape/pull/2326 ) : Use ActiveSupport extensions - [ @ericproulx ] ( https://github.com/ericproulx ) .
66* [ #2327 ] ( https://github.com/ruby-grape/grape/pull/2327 ) : Use ActiveSupport deprecation - [ @ericproulx ] ( https://github.com/ericproulx ) .
7+ * [ #2330 ] ( https://github.com/ruby-grape/grape/pull/2330 ) : Use ActiveSupport inflector - [ @ericproulx ] ( https://github.com/ericproulx ) .
78* Your contribution here.
89
910#### Fixes
Original file line number Diff line number Diff line change 2727require 'active_support/core_ext/object/duplicable'
2828require 'active_support/dependencies/autoload'
2929require 'active_support/deprecation'
30+ require 'active_support/inflector'
3031require 'active_support/notifications'
3132require 'i18n'
3233
Original file line number Diff line number Diff line change @@ -61,19 +61,11 @@ def validate!(params)
6161 raise Grape ::Exceptions ::ValidationArrayErrors . new ( array_errors ) if array_errors . any?
6262 end
6363
64- def self . convert_to_short_name ( klass )
65- ret = klass . name . gsub ( /::/ , '/' )
66- ret . gsub! ( /([A-Z]+)([A-Z][a-z])/ , '\1_\2' )
67- ret . gsub! ( /([a-z\d ])([A-Z])/ , '\1_\2' )
68- ret . tr! ( '-' , '_' )
69- ret . downcase!
70- File . basename ( ret , '_validator' )
71- end
72-
7364 def self . inherited ( klass )
7465 return if klass . name . blank?
7566
76- Validations . register_validator ( convert_to_short_name ( klass ) , klass )
67+ short_validator_name = klass . name . demodulize . underscore . delete_suffix! ( '_validator' )
68+ Validations . register_validator ( short_validator_name , klass )
7769 end
7870
7971 def message ( default_key = nil )
You can’t perform that action at this time.
0 commit comments