Welcome to mirror list, hosted at ThFree Co, Russian Federation.

custom_validators.rb « helpers « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd4f6c41131b67208ddc52599bcaf1129f4da641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)

          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)