Class: RuleRegistry
- Inherits:
-
Object
- Object
- RuleRegistry
- Defined in:
- lib/rule_registry.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#by_id(id) ⇒ Object
FATAL applies to multiple rules.
- #definition(id:, type:, message:) ⇒ Object
- #failings ⇒ Object
-
#initialize ⇒ RuleRegistry
constructor
A new instance of RuleRegistry.
- #warnings ⇒ Object
Constructor Details
#initialize ⇒ RuleRegistry
Returns a new instance of RuleRegistry.
7 8 9 |
# File 'lib/rule_registry.rb', line 7 def initialize @rules = [] end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
5 6 7 |
# File 'lib/rule_registry.rb', line 5 def rules @rules end |
Instance Method Details
#by_id(id) ⇒ Object
FATAL applies to multiple rules
27 28 29 |
# File 'lib/rule_registry.rb', line 27 def by_id(id) @rules.select { |rule| rule.id == id } end |
#definition(id:, type:, message:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rule_registry.rb', line 11 def definition(id:, type:, message:) violation_def = Violation.new(id: id, type: type, message: ) existing_def = @rules.find { |definition| definition == violation_def } if existing_def.nil? add_rule violation_def else existing_def end end |
#failings ⇒ Object
35 36 37 |
# File 'lib/rule_registry.rb', line 35 def failings @rules.select { |rule| rule.type == Violation::FAILING_VIOLATION } end |