Class: Menuconform::Catalog

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

Overview

Loads rules/catalog.json — the single source of truth for rule severities, titles, and fix hints.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Catalog

Returns a new instance of Catalog.



15
16
17
18
# File 'lib/menuconform/catalog.rb', line 15

def initialize(doc)
  @rules_version = doc.fetch("rules_version")
  @by_id = doc.fetch("rules").to_h { |r| [r.fetch("id"), r] }
end

Instance Attribute Details

#rules_versionObject (readonly)

Returns the value of attribute rules_version.



13
14
15
# File 'lib/menuconform/catalog.rb', line 13

def rules_version
  @rules_version
end

Class Method Details

.load(path) ⇒ Object



9
10
11
# File 'lib/menuconform/catalog.rb', line 9

def self.load(path)
  new(JSON.parse(File.read(path, encoding: "UTF-8")))
end

Instance Method Details

#entry(rule_id) ⇒ Object



20
21
22
# File 'lib/menuconform/catalog.rb', line 20

def entry(rule_id)
  @by_id.fetch(rule_id) { raise KeyError, "rule #{rule_id} is not in the catalog" }
end

#severity(rule_id) ⇒ Object



24
25
26
# File 'lib/menuconform/catalog.rb', line 24

def severity(rule_id)
  entry(rule_id).fetch("severity")
end