Class: Grape::Validations::AtLeastOneOfValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/grape/validations/at_least_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.



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

def params
  @params
end

Instance Method Details

#validate!(params) ⇒ Object



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

def validate!(params)
  @params = params
  if no_exclusive_params_are_present
    raise Grape::Exceptions::Validation, params: attrs.map(&:to_s), message_key: :at_least_one
  end
  params
end