Class: RuleRegistry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRuleRegistry

Returns a new instance of RuleRegistry.



7
8
9
# File 'lib/rule_registry.rb', line 7

def initialize
  @rules = []
end

Instance Attribute Details

#rulesObject (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: message)
  existing_def = @rules.find { |definition| definition == violation_def }

  if existing_def.nil?
    add_rule violation_def
  else
    existing_def
  end
end

#failingsObject



35
36
37
# File 'lib/rule_registry.rb', line 35

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

#warningsObject



31
32
33
# File 'lib/rule_registry.rb', line 31

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