Class: InputSanitizer::V2::CleanPayloadCollectionField

Inherits:
Object
  • Object
show all
Defined in:
lib/input_sanitizer/v2/clean_payload_collection_field.rb

Instance Method Summary collapse

Instance Method Details

#callObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/input_sanitizer/v2/clean_payload_collection_field.rb', line 2

def call
  return nil if options[:allow_nil] && data == nil

  validate_type
  validate_size

  result, errors = [], {}

  data.each_with_index do |value, idx|
    begin
      result << converter.call(value, options)
    rescue InputSanitizer::ValidationError => e
      errors[idx] = e
    end
  end

  if errors.any?
    raise InputSanitizer::CollectionError.new(errors)
  else
    result
  end
end