Sha256: 2ee377ca9a33d33a1f6b797d8b6ae4b1bf129194b4bf7c78fb1241302b552b8a

Contents?: true

Size: 574 Bytes

Versions: 2

Compression:

Stored size: 574 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, param: "#{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_sym)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
grape-security-0.8.0 lib/grape/validations/exactly_one_of.rb
grape-0.8.0 lib/grape/validations/exactly_one_of.rb