Sha256: 3b422ae3b3943c6f7e659972a895e0308f43250833003e648dfcf148ca08566f

Contents?: true

Size: 574 Bytes

Versions: 6

Compression:

Stored size: 574 Bytes

Contents

module Grape
  module Validations
    require 'grape/validations/validators/mutual_exclusion'
    class ExactlyOneOfValidator < MutualExclusionValidator
      def validate!(params)
        super
        if scope_requires_params && none_of_restricted_params_is_present
          fail Grape::Exceptions::Validation, params: all_keys, message_key: :exactly_one
        end
        params
      end

      private

      def none_of_restricted_params_is_present
        scoped_params.any? { |resource_params| keys_in_common(resource_params).empty? }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
grape-0.14.0 lib/grape/validations/validators/exactly_one_of.rb
grape-0.13.0 lib/grape/validations/validators/exactly_one_of.rb
grape-0.12.0 lib/grape/validations/validators/exactly_one_of.rb
grape-0.11.0 lib/grape/validations/validators/exactly_one_of.rb
grape-0.10.1 lib/grape/validations/validators/exactly_one_of.rb
grape-0.10.0 lib/grape/validations/validators/exactly_one_of.rb