Class: SensitiveDataFilter::Scan

Inherits:
Object
  • Object
show all
Defined in:
lib/sensitive_data_filter/scan.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Scan

Returns a new instance of Scan.



33
34
35
# File 'lib/sensitive_data_filter/scan.rb', line 33

def initialize(value)
  @value = value
end

Class Method Details

.scan(value) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/sensitive_data_filter/scan.rb', line 7

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

.scan_array(array) ⇒ Object



15
16
17
# File 'lib/sensitive_data_filter/scan.rb', line 15

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

.scan_hash(hash) ⇒ Object



19
20
21
# File 'lib/sensitive_data_filter/scan.rb', line 19

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

.scan_key_value(key, value) ⇒ Object



23
24
25
26
27
# File 'lib/sensitive_data_filter/scan.rb', line 23

def self.scan_key_value(key, value)
  key_scan = scan(key)
  return key_scan if SensitiveDataFilter.whitelisted_key? key
  key_scan.collate(scan(value))
end

.whitelist(matches) ⇒ Object



29
30
31
# File 'lib/sensitive_data_filter/scan.rb', line 29

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

Instance Method Details

#matchesObject



37
38
39
# File 'lib/sensitive_data_filter/scan.rb', line 37

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

#matches?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sensitive_data_filter/scan.rb', line 41

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