Class: Grape::Validations::MutualExclusionValidator

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

Direct Known Subclasses

ExactlyOneOfValidator

Instance Attribute Summary collapse

Attributes inherited from MultipleParamsBase

#scoped_params

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

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

Instance Attribute Details

#processing_keys_in_commonObject (readonly)

Returns the value of attribute processing_keys_in_common


5
6
7
# File 'lib/grape/validations/validators/mutual_exclusion.rb', line 5

def processing_keys_in_common
  @processing_keys_in_common
end

Instance Method Details

#validate!(params) ⇒ Object


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

def validate!(params)
  super
  if two_or_more_exclusive_params_are_present
    raise Grape::Exceptions::Validation, params: processing_keys_in_common, message: message(:mutual_exclusion)
  end
  params
end