Method: ActiveInteraction::ArrayFilter#process

Defined in:
lib/active_interaction/filters/array_filter.rb

#process(value, context) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_interaction/filters/array_filter.rb', line 41

def process(value, context)
  input = super

  return ArrayInput.new(self, value: input.value, error: input.errors.first) if input.errors.any?
  return ArrayInput.new(self, value: default(context), error: input.errors.first) if input.value.nil?

  value = input.value
  error = nil
  children = []

  unless filters.empty?
    value = value.map do |item|
      result = filters[:'0'].process(item, context)
      children.push(result)
      result.value
    end
  end

  ArrayInput.new(self, value: value, error: error, children: children, index_errors: index_errors?)
end