Class: ActiveInteraction::ArrayFilter

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

Overview

Since:

  • 1.0.0

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

rubocop:disable Style/MethodMissing

Since:

  • 1.0.0



43
44
45
46
47
48
49
50
51
# File 'lib/active_interaction/filters/array_filter.rb', line 43

def method_missing(*, &block) # rubocop:disable Style/MethodMissing
  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, context) ⇒ Object

Since:

  • 1.0.0



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_interaction/filters/array_filter.rb', line 31

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

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