Class: ActiveInteraction::ArrayFilter
- Includes:
- MethodMissing
- Defined in:
- lib/active_interaction/filters/array_filter.rb
Overview
Instance Attribute Summary
Attributes inherited from Filter
Instance Method Summary collapse
Methods inherited from Filter
#clean, #default, factory, #has_default?, inherited, #initialize, slug
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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_interaction/filters/array_filter.rb', line 43 def method_missing(*args, &block) super do |klass, names, | filter = klass.new(name, , &block) if filters.any? raise InvalidFilterError, 'multiple filters in array block' end unless names.empty? raise InvalidFilterError, 'attribute names in array block' end if filter.has_default? raise InvalidDefaultError, 'default values in array block' end filters.add(filter) end end |
Instance Method Details
#cast(value) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_interaction/filters/array_filter.rb', line 31 def cast(value) case value when Array return value if filters.none? filter = filters.first value.map { |e| filter.clean(e) } else super end end |