Class: Violation

Inherits:
RuleDefinition show all
Defined in:
lib/cfn-nag/violation.rb

Constant Summary

Constants inherited from RuleDefinition

RuleDefinition::FAILING_VIOLATION, RuleDefinition::WARNING

Instance Attribute Summary collapse

Attributes inherited from RuleDefinition

#id, #message, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RuleDefinition

#==

Constructor Details

#initialize(id:, type:, message:, logical_resource_ids: nil) ⇒ Violation

Returns a new instance of Violation.



6
7
8
9
10
11
12
13
14
15
# File 'lib/cfn-nag/violation.rb', line 6

def initialize(id:,
               type:,
               message:,
               logical_resource_ids: nil)
  super id: id,
        type: type,
        message: message

  @logical_resource_ids = logical_resource_ids
end

Instance Attribute Details

#logical_resource_idsObject (readonly)

Returns the value of attribute logical_resource_ids.



4
5
6
# File 'lib/cfn-nag/violation.rb', line 4

def logical_resource_ids
  @logical_resource_ids
end

Class Method Details

.count_failures(violations) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cfn-nag/violation.rb', line 40

def self.count_failures(violations)
  violations.inject(0) do |count, violation|
    if violation.type == Violation::FAILING_VIOLATION
      if empty?(violation.logical_resource_ids)
        count += 1
      else
        count += violation.logical_resource_ids.size
      end
    end
    count
  end
end

.count_warnings(violations) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cfn-nag/violation.rb', line 27

def self.count_warnings(violations)
  violations.inject(0) do |count, violation|
    if violation.type == Violation::WARNING
      if empty?(violation.logical_resource_ids)
        count += 1
      else
        count += violation.logical_resource_ids.size
      end
    end
    count
  end
end

Instance Method Details

#to_hObject



21
22
23
24
25
# File 'lib/cfn-nag/violation.rb', line 21

def to_h
  super.to_h.merge({
    logical_resource_ids: @logical_resource_ids
  })
end

#to_sObject



17
18
19
# File 'lib/cfn-nag/violation.rb', line 17

def to_s
  "#{super.to_s} #{@logical_resource_ids}"
end