Class: ActiveInteraction::HashFilter

Inherits:
Filter
  • Object
show all
Includes:
Missable
Defined in:
lib/active_interaction/filters/hash_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(*args, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/active_interaction/filters/hash_filter.rb', line 45

def method_missing(*args, &block)
  super(*args) do |klass, names, options|
    fail InvalidFilterError, 'missing attribute name' if names.empty?

    names.each do |name|
      filters[name] = klass.new(name, options, &block)
    end
  end
end

Instance Method Details

#cast(value) ⇒ Object



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

def cast(value)
  case value
  when Hash
    value = stringify_the_symbol_keys(value)

    filters.each_with_object(strip? ? {} : value) do |(name, filter), h|
      clean_value(h, name.to_s, filter, value)
    end.symbolize_keys
  else
    super
  end
end