Class: RuleRegistry
Overview
This registry contains all the discovered rule classes that are to be used for inspection.
Historically this just kept the metadata around the rules that percolated into the violation reports. This is no longer true as the rule discovery logic is being split out to support multiple discover algorithms (i.e. rule repositories). The CustomRuleLoader asks the discovery delegate to the rule classes, and that discovery returns this object with the rule definitions, and the class itself that can be invoked to do an inspection
Instance Attribute Summary collapse
-
#duplicate_ids ⇒ Object
readonly
Returns the value of attribute duplicate_ids.
-
#rule_classes ⇒ Object
readonly
Returns the value of attribute rule_classes.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #by_id(id) ⇒ Object
- #definition(rule_class) ⇒ Object
- #duplicate_ids? ⇒ Boolean
- #failings ⇒ Object
- #ids ⇒ Object
-
#initialize ⇒ RuleRegistry
constructor
A new instance of RuleRegistry.
- #merge!(other_rule_registry) ⇒ Object
- #warnings ⇒ Object
Constructor Details
#initialize ⇒ RuleRegistry
Returns a new instance of RuleRegistry.
20 21 22 23 24 |
# File 'lib/cfn-nag/rule_registry.rb', line 20 def initialize @rules = [] @duplicate_ids = [] @rule_classes = Set.new end |
Instance Attribute Details
#duplicate_ids ⇒ Object (readonly)
Returns the value of attribute duplicate_ids.
18 19 20 |
# File 'lib/cfn-nag/rule_registry.rb', line 18 def duplicate_ids @duplicate_ids end |
#rule_classes ⇒ Object (readonly)
Returns the value of attribute rule_classes.
18 19 20 |
# File 'lib/cfn-nag/rule_registry.rb', line 18 def rule_classes @rule_classes end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
18 19 20 |
# File 'lib/cfn-nag/rule_registry.rb', line 18 def rules @rules end |
Instance Method Details
#by_id(id) ⇒ Object
59 60 61 |
# File 'lib/cfn-nag/rule_registry.rb', line 59 def by_id(id) @rules.find { |rule| rule.id == id } end |
#definition(rule_class) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cfn-nag/rule_registry.rb', line 36 def definition(rule_class) @rule_classes.add rule_class rule = rule_class.new existing_def = by_id rule.rule_id if existing_def.nil? rule_definition = RuleDefinition.new( id: rule.rule_id, type: rule.rule_type, message: rule.rule_text ) add_rule rule_definition else @duplicate_ids << { id: rule.rule_id, new_message: rule.rule_text, registered_message: existing_def. } end end |
#duplicate_ids? ⇒ Boolean
26 27 28 |
# File 'lib/cfn-nag/rule_registry.rb', line 26 def duplicate_ids? @duplicate_ids.count.positive? end |
#failings ⇒ Object
71 72 73 |
# File 'lib/cfn-nag/rule_registry.rb', line 71 def failings @rules.select { |rule| rule.type == RuleDefinition::FAILING_VIOLATION } end |
#ids ⇒ Object
63 64 65 |
# File 'lib/cfn-nag/rule_registry.rb', line 63 def ids @rules.map(&:id) end |
#merge!(other_rule_registry) ⇒ Object
30 31 32 33 34 |
# File 'lib/cfn-nag/rule_registry.rb', line 30 def merge!(other_rule_registry) @rules += other_rule_registry.rules @duplicate_ids += other_rule_registry.duplicate_ids @rule_classes += other_rule_registry.rule_classes end |
#warnings ⇒ Object
67 68 69 |
# File 'lib/cfn-nag/rule_registry.rb', line 67 def warnings @rules.select { |rule| rule.type == RuleDefinition::WARNING } end |