Class: Grape::Validations::Validators::ExactlyOneOfValidator

Inherits:
MultipleParamsBase show all
Defined in:
lib/grape/validations/validators/exactly_one_of_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from MultipleParamsBase

#validate!

Methods inherited from Base

#fail_fast?, inherited, #initialize, #message, #options_key?, #validate, #validate!

Constructor Details

This class inherits a constructor from Grape::Validations::Validators::Base

Instance Method Details

#validate_params!(params) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/grape/validations/validators/exactly_one_of_validator.rb', line 7

def validate_params!(params)
  keys = keys_in_common(params)
  return if keys.length == 1
  raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.length.zero?

  raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
end