class ActiveInteraction::HashFilter

@private

Private Instance Methods

adjust_output(value, context) click to toggle source
# File lib/active_interaction/filters/hash_filter.rb, line 46
def adjust_output(value, context)
  value = ActiveSupport::HashWithIndifferentAccess.new(value.to_hash)

  initial = strip? ? ActiveSupport::HashWithIndifferentAccess.new : value

  filters.each_with_object(initial) do |(name, filter), hash|
    clean_value(hash, name.to_s, filter, value, context)
  end
end
clean_value(hash, name, filter, value, context) click to toggle source
# File lib/active_interaction/filters/hash_filter.rb, line 36
def clean_value(hash, name, filter, value, context)
  hash[name] = filter.clean(value[name], context)
rescue InvalidValueError, MissingValueError
  raise InvalidNestedValueError.new(name, value[name])
end
convert(value) click to toggle source
Calls superclass method ActiveInteraction::Filter#convert
# File lib/active_interaction/filters/hash_filter.rb, line 56
def convert(value)
  if value.respond_to?(:to_hash)
    value.to_hash
  else
    super
  end
rescue NoMethodError # BasicObject
  super
end
matches?(value) click to toggle source
# File lib/active_interaction/filters/hash_filter.rb, line 30
def matches?(value)
  value.is_a?(Hash)
rescue NoMethodError # BasicObject
  false
end
method_missing(*args, &block) click to toggle source

rubocop:disable Style/MissingRespondToMissing

# File lib/active_interaction/filters/hash_filter.rb, line 67
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 78
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 42
def strip?
  options.fetch(:strip, true)
end