Sha256: 40789a178b9c5faf27b83c829e1e37e2177ec33b2b379a77a75edad4130445e8

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module Grape
  module Validations
    class MultipleParamsBase < Base
      def validate!(params)
        attributes = MultipleAttributesIterator.new(self, @scope, params)
        array_errors = []

        attributes.each do |resource_params, skip_value|
          next if skip_value
          begin
            validate_params!(resource_params)
          rescue Grape::Exceptions::Validation => e
            array_errors << e
          end
        end

        raise Grape::Exceptions::ValidationArrayErrors, array_errors if array_errors.any?
      end

      private

      def keys_in_common(resource_params)
        return [] unless resource_params.is_a?(Hash)
        all_keys & resource_params.keys.map! { |attr| @scope.full_name(attr) }
      end

      def all_keys
        attrs.map { |attr| @scope.full_name(attr) }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grape-1.5.2 lib/grape/validations/validators/multiple_params_base.rb
grape-1.5.1 lib/grape/validations/validators/multiple_params_base.rb