@@ -331,30 +331,23 @@ def validates(attrs, validations)
331331 doc . type = coerce_type
332332
333333 default = validations [ :default ]
334-
335- if ( values_hash = validations [ :values ] ) . is_a? Hash
336- values = values_hash [ :value ]
337- # NB: excepts is deprecated
338- excepts = values_hash [ :except ]
339- else
340- values = validations [ :values ]
341- end
334+ values = validations [ :values ] . is_a? ( Hash ) ? validations . dig ( :values , :value ) : validations [ :values ]
342335
343336 doc . values = values
344337
345- except_values = options_key? ( :except_values , :value , validations ) ? validations [ :except_values ] [ :value ] : validations [ :except_values ]
338+ except_values = validations [ :except_values ] . is_a? ( Hash ) ? validations . dig ( :except_values , :value ) : validations [ :except_values ]
346339
347340 # NB. values and excepts should be nil, Proc, Array, or Range.
348341 # Specifically, values should NOT be a Hash
349342
350343 # use values or excepts to guess coerce type when stated type is Array
351- coerce_type = guess_coerce_type ( coerce_type , values , except_values , excepts )
344+ coerce_type = guess_coerce_type ( coerce_type , values , except_values )
352345
353346 # default value should be present in values array, if both exist and are not procs
354- check_incompatible_option_values ( default , values , except_values , excepts )
347+ check_incompatible_option_values ( default , values , except_values )
355348
356349 # type should be compatible with values array, if both exist
357- validate_value_coercion ( coerce_type , values , except_values , excepts )
350+ validate_value_coercion ( coerce_type , values , except_values )
358351
359352 doc . document attrs
360353
@@ -462,18 +455,14 @@ def guess_coerce_type(coerce_type, *values_list)
462455 coerce_type
463456 end
464457
465- def check_incompatible_option_values ( default , values , except_values , excepts )
458+ def check_incompatible_option_values ( default , values , except_values )
466459 return unless default && !default . is_a? ( Proc )
467460
468461 raise Grape ::Exceptions ::IncompatibleOptionValues . new ( :default , default , :values , values ) if values && !values . is_a? ( Proc ) && !Array ( default ) . all? { |def_val | values . include? ( def_val ) }
469462
470- if except_values && !except_values . is_a? ( Proc ) && Array ( default ) . any? { |def_val | except_values . include? ( def_val ) }
471- raise Grape ::Exceptions ::IncompatibleOptionValues . new ( :default , default , :except , except_values )
472- end
463+ return unless except_values && !except_values . is_a? ( Proc ) && Array ( default ) . any? { |def_val | except_values . include? ( def_val ) }
473464
474- return unless excepts && !excepts . is_a? ( Proc )
475- raise Grape ::Exceptions ::IncompatibleOptionValues . new ( :default , default , :except , excepts ) \
476- unless Array ( default ) . none? { |def_val | excepts . include? ( def_val ) }
465+ raise Grape ::Exceptions ::IncompatibleOptionValues . new ( :default , default , :except , except_values )
477466 end
478467
479468 def validate ( type , options , attrs , doc , opts )
0 commit comments