Sha256: a42829e87be4d2bb3cfeec8486bc5bd895ab1fd686d70486673e0c294dfd78f9

Contents?: true

Size: 598 Bytes

Versions: 1

Compression:

Stored size: 598 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

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.14.0 lib/grape/validations/validators/all_or_none.rb