Class: API::Validations::Validators::CheckAssigneesCount

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.coerceObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/api/validations/validators/check_assignees_count.rb', line 7

def self.coerce
  lambda do |value|
    case value
    when String, Array
      Array.wrap(value)
    else
      []
    end
  end
end

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object

Raises:

  • (Grape::Exceptions::Validation)


18
19
20
21
22
23
24
25
# File 'lib/api/validations/validators/check_assignees_count.rb', line 18

def validate_param!(attr_name, params)
  return if param_allowed?(attr_name, params)

  raise Grape::Exceptions::Validation.new(
    params: [@scope.full_name(attr_name)],
    message: "allows one value, but found #{params[attr_name].size}: #{params[attr_name].join(", ")}"
  )
end