Sha256: 613bf05a9bba8d01b7baad9ccb53ceba7ccf47c89cb9d4f4c533cfe63ec0a02d

Contents?: true

Size: 568 Bytes

Versions: 1

Compression:

Stored size: 568 Bytes

Contents

module Grape
  module Validations
    require 'grape/validations/mutual_exclusion'
    class ExactlyOneOfValidator < MutualExclusionValidator
      attr_reader :params

      def validate!(params)
        super
        if none_of_restricted_params_is_present
          raise Grape::Exceptions::Validation, params: all_keys, message_key: :exactly_one
        end
        params
      end

      private

      def none_of_restricted_params_is_present
        keys_in_common.length < 1
      end

      def all_keys
        attrs.map(&:to_s)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.9.0 lib/grape/validations/exactly_one_of.rb