class ActiveInteraction::HashFilter
@private
Public Instance Methods
process(value, context)
click to toggle source
Calls superclass method
ActiveInteraction::Filter#process
# File lib/active_interaction/filters/hash_filter.rb, line 28 def process(value, context) # rubocop:disable Metrics/AbcSize input = super return HashInput.new(self, value: input.value, error: input.errors.first) if input.errors.first return HashInput.new(self, value: default(context), error: input.errors.first) if input.value.nil? value = strip? ? HashWithIndifferentAccess.new : input.value error = nil children = {} filters.each do |name, filter| if filter.options[:default].is_a?(Proc) && !options[:default].is_a?(Proc) raise InvalidDefaultError, "#{self.name}: must use a lazy default if any nested filter uses a lazy default" end filter.process(input.value[name], context).tap do |result| value[name] = result.value children[name.to_sym] = result end end HashInput.new(self, value: value, error: error, children: children) end
Private Instance Methods
adjust_output(value, _context)
click to toggle source
# File lib/active_interaction/filters/hash_filter.rb, line 64 def adjust_output(value, _context) ActiveSupport::HashWithIndifferentAccess.new(value) end
convert(value)
click to toggle source
Calls superclass method
ActiveInteraction::Filter#convert
# File lib/active_interaction/filters/hash_filter.rb, line 68 def convert(value) if value.respond_to?(:to_hash) [value.to_hash, nil] else super end rescue NoMethodError # BasicObject super end
matches?(value)
click to toggle source
# File lib/active_interaction/filters/hash_filter.rb, line 54 def matches?(value) value.is_a?(Hash) rescue NoMethodError # BasicObject false end
method_missing(*args, &block)
click to toggle source
rubocop:disable Style/MissingRespondToMissing
Calls superclass method
ActiveInteraction::Missable#method_missing
# File lib/active_interaction/filters/hash_filter.rb, line 79 def method_missing(*args, &block) super(*args) do |klass, names, options| raise InvalidFilterError, 'missing attribute name' if names.empty? names.each do |name| filters[name] = klass.new(name, options, &block) end end end
raw_default(*)
click to toggle source
rubocop:enable Style/MissingRespondToMissing
Calls superclass method
ActiveInteraction::Filter#raw_default
# File lib/active_interaction/filters/hash_filter.rb, line 90 def raw_default(*) value = super raise InvalidDefaultError, "#{name}: #{value.inspect}" if value.is_a?(Hash) && !value.empty? value end
strip?()
click to toggle source
# File lib/active_interaction/filters/hash_filter.rb, line 60 def strip? options.fetch(:strip, true) end