Sha256: bb195873bf8dd387065ae30ebfabc0630793f2d5b1ebba9f8c060dfed4bcee93

Contents?: true

Size: 723 Bytes

Versions: 15

Compression:

Stored size: 723 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
          raise 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

15 entries across 15 versions & 1 rubygems

Version Path
grape-1.2.4 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.2.3 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.2.2 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.2.1 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.2.0 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.1.0 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.0.3 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.0.2 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.0.1 lib/grape/validations/validators/mutual_exclusion.rb
grape-1.0.0 lib/grape/validations/validators/mutual_exclusion.rb
grape-0.19.2 lib/grape/validations/validators/mutual_exclusion.rb
grape-0.19.1 lib/grape/validations/validators/mutual_exclusion.rb
grape-0.19.0 lib/grape/validations/validators/mutual_exclusion.rb
grape-0.18.0 lib/grape/validations/validators/mutual_exclusion.rb
grape-0.17.0 lib/grape/validations/validators/mutual_exclusion.rb