Class: ActiveInteraction::HashFilter
- Includes:
- Missable
- Defined in:
- lib/active_interaction/filters/hash_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(*args, &block) ⇒ Object (private)
rubocop:disable Style/MissingRespondToMissing
75 76 77 78 79 80 81 82 83 |
# File 'lib/active_interaction/filters/hash_filter.rb', line 75 def method_missing(*args, &block) super(*args) do |klass, names, | raise InvalidFilterError, 'missing attribute name' if names.empty? names.each do |name| filters[name] = klass.new(name, , &block) end end end |
Instance Method Details
#process(value, context) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_interaction/filters/hash_filter.rb', line 28 def process(value, context) input = super return HashInput.new(self, value: input.value, error: input.errors.first) if input.errors.first return HashInput.new(self, value: default(context), error: input.errors.first) if input.value.nil? value = strip? ? HashWithIndifferentAccess.new : input.value error = nil children = {} filters.each do |name, filter| filter.process(input.value[name], context).tap do |result| value[name] = result.value children[name.to_sym] = result end end HashInput.new(self, value: value, error: error, children: children) end |