Sha256: ce6f77c64f5584848fd49637157a679c2b548e7d25ec843573dd9d8b08229935

Contents?: true

Size: 979 Bytes

Versions: 5

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true
require 'facets/kernel/present'
require 'facets/hash/collate'

module SensitiveDataFilter
  class Scan
    def self.scan(value)
      return scan_array(value) if value.is_a? Array
      return scan_hash(value) if value.is_a? Hash
      SensitiveDataFilter.enabled_types.map.with_object({}) { |scanner, matches|
        matches[scanner.name.split('::').last] = whitelist(scanner.scan(value))
      }
    end

    def self.scan_array(array)
      array.map { |element| scan(element) }.inject(:collate) || {}
    end

    def self.scan_hash(hash)
      hash.map { |key, value| scan(key).collate(scan(value)) }.inject(:collate) || {}
    end

    def self.whitelist(matches)
      matches.reject { |match| SensitiveDataFilter.whitelisted? match }
    end

    def initialize(value)
      @value = value
    end

    def matches
      @matches ||= self.class.scan(@value)
    end

    def matches?
      matches.values.any?(&:present?)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sensitive_data_filter-0.2.4 lib/sensitive_data_filter/scan.rb
sensitive_data_filter-0.2.3 lib/sensitive_data_filter/scan.rb
sensitive_data_filter-0.2.2 lib/sensitive_data_filter/scan.rb
sensitive_data_filter-0.2.1 lib/sensitive_data_filter/scan.rb
sensitive_data_filter-0.2.0 lib/sensitive_data_filter/scan.rb