Class: Cased::Sensitive::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/cased/sensitive/processor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audit_event, handlers) ⇒ Processor

Returns a new instance of Processor.



26
27
28
29
30
# File 'lib/cased/sensitive/processor.rb', line 26

def initialize(audit_event, handlers)
  @audit_event = audit_event.dup.freeze
  @ranges = []
  @handlers = handlers
end

Instance Attribute Details

#audit_eventObject (readonly)

Returns the value of attribute audit_event.



24
25
26
# File 'lib/cased/sensitive/processor.rb', line 24

def audit_event
  @audit_event
end

#handlersObject (readonly)

Returns the value of attribute handlers.



24
25
26
# File 'lib/cased/sensitive/processor.rb', line 24

def handlers
  @handlers
end

Class Method Details

.process(audit_event, handlers = nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/cased/sensitive/processor.rb', line 8

def self.process(audit_event, handlers = nil)
  handlers ||= Cased::Sensitive::Handler.handlers
  processor = new(audit_event, handlers)
  processor.process
  processor
end

.process!(audit_event, handlers = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/cased/sensitive/processor.rb', line 15

def self.process!(audit_event, handlers = nil)
  processor = process(audit_event, handlers)
  return unless processor.sensitive?

  audit_event[:'.cased'] = {
    pii: processor.to_h,
  }
end

Instance Method Details

#processObject



32
33
34
35
36
37
# File 'lib/cased/sensitive/processor.rb', line 32

def process
  return true if defined?(@processed)

  walk(audit_event)
  @processed = true
end

#rangesObject



39
40
41
# File 'lib/cased/sensitive/processor.rb', line 39

def ranges
  @ranges.flatten
end

#sensitive?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cased/sensitive/processor.rb', line 43

def sensitive?
  process && ranges.any?
end

#to_hObject



47
48
49
50
51
52
53
54
# File 'lib/cased/sensitive/processor.rb', line 47

def to_h
  results = {}
  ranges.each do |range|
    results[range.key] ||= []
    results[range.key] << range.to_h
  end
  results
end