Class: ActiveInteraction::ArrayFilter
- Includes:
- Missable
- Defined in:
- lib/active_interaction/filters/array_filter.rb
Instance Attribute Summary
Attributes inherited from Filter
Instance Method Summary collapse
Methods inherited from Filter
#accepts_grouped_inputs?, #database_column_type, #default, #default?, #desc, factory, #initialize
Constructor Details
This class inherits a constructor from ActiveInteraction::Filter
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(&block) ⇒ Object (private)
rubocop:disable Style/MissingRespondToMissing
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/active_interaction/filters/array_filter.rb', line 120 def method_missing(*, &block) super do |klass, names, | = add_option_in_place_of_name(klass, ) filter = klass.new(names.first || '', , &block) filters[filters.size.to_s.to_sym] = filter validate!(names) end end |
Instance Method Details
#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 |