Sha256: 15f327725f85ca6e6b9d5d92e85550bdeaf4eb6d5a836dc98a22bb23789df315

Contents?: true

Size: 968 Bytes

Versions: 35

Compression:

Stored size: 968 Bytes

Contents

# TaskArgumentFilterer will recursively walk any arguemnts to a task and filter any
# hashes with a filtered key.  By default only :password is filtered, but you can add
# more with Volt.config.filter_keys
class TaskArgumentFilterer
  def self.filter(args)
    new(args).run
  end

  def initialize(args)
    # # Cache the filter args
    @@filter_args ||= begin
      # Load, with default, convert to symbols
      arg_names = (Volt.config.filter_keys || [:password]).map(&:to_sym)
    end

    @args = args
  end

  def run
    filter_args(@args)
  end

  private

  def filter_args(args)
    if args.is_a?(Array)
      args.map { |v| filter_args(v) }
    elsif args.is_a?(Hash)
      args.map do |k, v|
        if @@filter_args.include?(k.to_sym)
          # filter
          [k, '[FILTERED]']
        else
          # retunr unfiltered
          [k, filter_args(v)]
        end
      end.to_h # <= convert back to hash
    else
      return args
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
volt-0.9.7.pre8 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.7.pre7 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.7.pre6 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.7.pre5 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.7.pre3 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.7.pre2 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.6 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.6.pre3 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.6.pre2 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.6.pre1 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre12 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre11 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre9 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre8 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre7 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre6 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre5 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre4 lib/volt/utils/logging/task_argument_filterer.rb
volt-0.9.5.pre3 lib/volt/utils/logging/task_argument_filterer.rb