Sha256: a9ad1db14f1c691034b874c3ffc3fdf43454333fbf38a1742d3dc72a7a6a0738

Contents?: true

Size: 534 Bytes

Versions: 1

Compression:

Stored size: 534 Bytes

Contents

# frozen_string_literal: true

require 'grape/validations/validators/multiple_params_base'

module Grape
  module Validations
    class ExactlyOneOfValidator < MultipleParamsBase
      def validate_params!(params)
        keys = keys_in_common(params)
        return if keys.length == 1
        raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.length.zero?

        raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-1.6.0 lib/grape/validations/validators/exactly_one_of.rb