Sha256: 01e6a850549228b8eaacf6d62df7c7f5ac633a47d03793b7d9d0ba245b7309b4

Contents?: true

Size: 908 Bytes

Versions: 4

Compression:

Stored size: 908 Bytes

Contents

module Rack::ActionLogger
  module ParameterFiltering
    FILTERED = '[FILTERED]'.freeze # :nodoc:

    class << self

      def apply_filter(original_params)
        filtered_params = {}

        original_params.each do |key, value|
          if compiled_filters.any? { |r| key =~ r }
            value = FILTERED
          elsif value.is_a?(Hash)
            value = apply_filter(value)
          elsif value.is_a?(Array)
            value = value.map { |v| v.is_a?(Hash) ? apply_filter(v) : v }
          end

          filtered_params[key] = value
        end

        filtered_params
      end

      private

      def compiled_filters
        @compiled_filters ||= compile(Rack::ActionLogger.configuration.filters)
      end

      def compile(filters)
        filter_strings = filters.map(&:to_s)
        filter_strings.map { |item| Regexp.compile(Regexp.escape(item)) }
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rack-action_logger-0.4.0 lib/rack/action_logger/parameter_filtering.rb
rack-action_logger-0.3.0 lib/rack/action_logger/parameter_filtering.rb
rack-action_logger-0.2.0 lib/rack/action_logger/parameter_filtering.rb
rack-action_logger-0.1.9 lib/rack/action_logger/parameter_filtering.rb