Class: Grape::Validations::ExactlyOneOfValidator

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

Instance Attribute Summary

Attributes inherited from MutualExclusionValidator

#processing_keys_in_common

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, #options_key?, #validate

Constructor Details

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

Instance Method Details

#message(default_key = nil) ⇒ Object


13
14
15
16
17
18
19
20
# File 'lib/grape/validations/validators/exactly_one_of.rb', line 13

def message(default_key = nil)
  options = instance_variable_get(:@option)
  if options_key?(:message)
    (options_key?(default_key, options[:message]) ? options[:message][default_key] : options[:message])
  else
    default_key
  end
end

#validate!(params) ⇒ Object


5
6
7
8
9
10
11
# File 'lib/grape/validations/validators/exactly_one_of.rb', line 5

def validate!(params)
  super
  if scope_requires_params && none_of_restricted_params_is_present
    raise Grape::Exceptions::Validation, params: all_keys, message: message(:exactly_one)
  end
  params
end