File: multiple_params_base.rb

package info (click to toggle)
ruby-grape 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,156 kB
  • sloc: ruby: 25,265; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 969 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

module Grape
  module Validations
    module Validators
      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.new(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
end