Class: ActiveInteraction::ArrayFilter

Inherits:
Filter
  • Object
show all
Includes:
Missable
Defined in:
lib/active_interaction/filters/array_filter.rb

Instance Attribute Summary

Attributes inherited from Filter

#filters, #name, #options

Instance Method Summary collapse

Methods inherited from Filter

#clean, #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



47
48
49
50
51
52
53
54
55
# File 'lib/active_interaction/filters/array_filter.rb', line 47

def method_missing(*, &block)
  super do |klass, names, options|
    filter = klass.new(name.to_s.singularize.to_sym, options, &block)

    validate(filter, names)

    filters[filter.name] = filter
  end
end

Instance Method Details

#cast(value) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_interaction/filters/array_filter.rb', line 35

def cast(value)
  case value
  when *classes
    return value if filters.empty?

    filter = filters.values.first
    value.map { |e| filter.clean(e) }
  else
    super
  end
end