Sha256: 3905e89db5f2f63f8114f6e022087665dc400d991d5dbdee10f5a531d4498c28

Contents?: true

Size: 722 Bytes

Versions: 3

Compression:

Stored size: 722 Bytes

Contents

module Grape
  module Validations
    require 'grape/validations/validators/multiple_params_base'
    class MutualExclusionValidator < MultipleParamsBase
      attr_reader :processing_keys_in_common

      def validate!(params)
        super
        if two_or_more_exclusive_params_are_present
          fail Grape::Exceptions::Validation, params: processing_keys_in_common, message: message(:mutual_exclusion)
        end
        params
      end

      private

      def two_or_more_exclusive_params_are_present
        scoped_params.any? do |resource_params|
          @processing_keys_in_common = keys_in_common(resource_params)
          @processing_keys_in_common.length > 1
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-0.16.2 lib/grape/validations/validators/mutual_exclusion.rb
grape-0.16.1 lib/grape/validations/validators/mutual_exclusion.rb
grape-0.15.0 lib/grape/validations/validators/mutual_exclusion.rb