Class: Grape::Validations::ExactlyOneOfValidator

Inherits:
MutualExclusionValidator show all
Defined in:
lib/grape/validations/exactly_one_of.rb

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


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

def params
  @params
end

Instance Method Details

#validate!(params) ⇒ Object


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

def validate!(params)
  super
  if none_of_restricted_params_is_present
    raise Grape::Exceptions::Validation, param: "#{all_keys}", message_key: :exactly_one
  end
  params
end