Sha256: 2b6736c0136df0d4c5263b541df8cf2178dd08e4896cf307a109bdff4a54b0fe

Contents?: true

Size: 563 Bytes

Versions: 6

Compression:

Stored size: 563 Bytes

Contents

module Grape
  module Validations
    require 'grape/validations/validators/multiple_params_base'
    class AtLeastOneOfValidator < MultipleParamsBase
      def validate!(params)
        super
        if scope_requires_params && no_exclusive_params_are_present
          fail Grape::Exceptions::Validation, params: all_keys, message_key: :at_least_one
        end
        params
      end

      private

      def no_exclusive_params_are_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/at_least_one_of.rb
grape-0.13.0 lib/grape/validations/validators/at_least_one_of.rb
grape-0.12.0 lib/grape/validations/validators/at_least_one_of.rb
grape-0.11.0 lib/grape/validations/validators/at_least_one_of.rb
grape-0.10.1 lib/grape/validations/validators/at_least_one_of.rb
grape-0.10.0 lib/grape/validations/validators/at_least_one_of.rb