Class: RuleRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/cfn-nag/rule_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRuleRegistry

Returns a new instance of RuleRegistry.



8
9
10
11
# File 'lib/cfn-nag/rule_registry.rb', line 8

def initialize
  @rules = []
  @duplicate_ids = []
end

Instance Attribute Details

#duplicate_idsObject (readonly)

Returns the value of attribute duplicate_ids.



6
7
8
# File 'lib/cfn-nag/rule_registry.rb', line 6

def duplicate_ids
  @duplicate_ids
end

#rulesObject (readonly)

Returns the value of attribute rules.



6
7
8
# File 'lib/cfn-nag/rule_registry.rb', line 6

def rules
  @rules
end

Instance Method Details

#by_id(id) ⇒ Object



36
37
38
# File 'lib/cfn-nag/rule_registry.rb', line 36

def by_id(id)
  @rules.find { |rule| rule.id == id }
end

#definition(id:, type:, message:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cfn-nag/rule_registry.rb', line 17

def definition(id:,
               type:,
               message:)
  rule_definition = RuleDefinition.new(id: id,
                                       type: type,
                                       message: message)
  existing_def = by_id id

  if existing_def.nil?
    add_rule rule_definition
  else
    @duplicate_ids << {
      id: id,
      new_message: message,
      registered_message: existing_def.message
    }
  end
end

#duplicate_ids?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cfn-nag/rule_registry.rb', line 13

def duplicate_ids?
  @duplicate_ids.count.positive?
end

#failingsObject



44
45
46
# File 'lib/cfn-nag/rule_registry.rb', line 44

def failings
  @rules.select { |rule| rule.type == RuleDefinition::FAILING_VIOLATION }
end

#warningsObject



40
41
42
# File 'lib/cfn-nag/rule_registry.rb', line 40

def warnings
  @rules.select { |rule| rule.type == RuleDefinition::WARNING }
end