Sha256: 0de27835ec74c93936beb3b640c47ab1ef76c9f67745a7a319b16a8eac2cfe8a

Contents?: true

Size: 599 Bytes

Versions: 5

Compression:

Stored size: 599 Bytes

Contents

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

      private

      def only_subset_present
        scoped_params.any? { |resource_params| keys_in_common(resource_params).length > 0 && keys_in_common(resource_params).length < attrs.length  }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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