Class: API::Validations::Validators::EmailOrEmailList

Inherits:
Grape::Validations::Validators::Base
  • Object
show all
Defined in:
lib/api/validations/validators/email_or_email_list.rb

Instance Method Summary collapse

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object

Raises:

  • (Grape::Exceptions::Validation)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/api/validations/validators/email_or_email_list.rb', line 7

def validate_param!(attr_name, params)
  value = params[attr_name]

  return unless value

  case value
  when String
    return if value.split(',').map { |v| ValidateEmail.valid?(v) }.all?
  when Array
    return if value.map { |v| ValidateEmail.valid?(v) }.all?
  end

  raise Grape::Exceptions::Validation.new(
    params: [@scope.full_name(attr_name)],
    message: "contains an invalid email address"
  )
end