gitlab-org--gitlab-foss/lib/api/helpers/custom_validators.rb

16 lines
469 B
Ruby
Raw Normal View History

2016-12-07 20:09:18 -05:00
module API
module Helpers
module CustomValidators
class Absence < Grape::Validations::Base
def validate_param!(attr_name, params)
return if params.respond_to?(:key?) && !params.key?(attr_name)
2016-12-07 20:09:18 -05:00
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:absence)
end
end
end
end
end
Grape::Validations.register_validator(:absence, ::API::Helpers::CustomValidators::Absence)