Sha256: 491ff0a172e1efdbcfdb72b5f39036eff03325eb16566add006866234d0b1f09

Contents?: true

Size: 601 Bytes

Versions: 15

Compression:

Stored size: 601 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
          raise Grape::Exceptions::Validation, params: all_keys, message: message(:all_or_none)
        end
        params
      end

      private

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grape-1.2.4 lib/grape/validations/validators/all_or_none.rb
grape-1.2.3 lib/grape/validations/validators/all_or_none.rb
grape-1.2.2 lib/grape/validations/validators/all_or_none.rb
grape-1.2.1 lib/grape/validations/validators/all_or_none.rb
grape-1.2.0 lib/grape/validations/validators/all_or_none.rb
grape-1.1.0 lib/grape/validations/validators/all_or_none.rb
grape-1.0.3 lib/grape/validations/validators/all_or_none.rb
grape-1.0.2 lib/grape/validations/validators/all_or_none.rb
grape-1.0.1 lib/grape/validations/validators/all_or_none.rb
grape-1.0.0 lib/grape/validations/validators/all_or_none.rb
grape-0.19.2 lib/grape/validations/validators/all_or_none.rb
grape-0.19.1 lib/grape/validations/validators/all_or_none.rb
grape-0.19.0 lib/grape/validations/validators/all_or_none.rb
grape-0.18.0 lib/grape/validations/validators/all_or_none.rb
grape-0.17.0 lib/grape/validations/validators/all_or_none.rb