Class: ActiveInteraction::HashFilter
- Includes:
- Missable
- Defined in:
- lib/active_interaction/filters/hash_filter.rb
Overview
Instance Attribute Summary
Attributes inherited from Filter
Instance Method Summary collapse
- #cast(value, context) ⇒ Object
-
#method_missing(*args, &block) ⇒ Object
rubocop:disable Style/MethodMissing.
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
rubocop:disable Style/MethodMissing
43 44 45 46 47 48 49 50 51 |
# File 'lib/active_interaction/filters/hash_filter.rb', line 43 def method_missing(*args, &block) # rubocop:disable Style/MethodMissing 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
#cast(value, context) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_interaction/filters/hash_filter.rb', line 29 def cast(value, context) case value when Hash value = value.with_indifferent_access initial = strip? ? ActiveSupport::HashWithIndifferentAccess.new : value filters.each_with_object(initial) do |(name, filter), h| clean_value(h, name.to_s, filter, value, context) end else super end end |