Class: Grape::Validations::MutualExclusionValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/grape/validations/mutual_exclusion.rb

Direct Known Subclasses

ExactlyOneOfValidator

Instance Attribute Summary collapse

Attributes inherited from Validator

#attrs

Instance Method Summary collapse

Methods inherited from Validator

convert_to_short_name, inherited, #initialize

Constructor Details

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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#validate!(params) ⇒ Object



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

def validate!(params)
  @params = params
  if two_or_more_exclusive_params_are_present
    raise Grape::Exceptions::Validation, params: keys_in_common, message_key: :mutual_exclusion
  end
  params
end