Class: RuboCounsel::CopCatalog
- Inherits:
-
Object
- Object
- RuboCounsel::CopCatalog
- Defined in:
- lib/rubocounsel/cop_catalog.rb
Overview
Central repository of cop information. Uses RuboCop's Registry for cop discovery and ExampleLoader for documentation.
The Registry is RuboCop's authoritative cop list - stable and complete. Examples come from YARD parsing (separate concern, can fail gracefully).
Constant Summary collapse
- EXCLUDED_COP_DEPARTMENTS =
InternalAffairs cops are for RuboCop development, not end users.
["InternalAffairs"].freeze
Instance Method Summary collapse
-
#cops ⇒ Object
Returns a Hash where keys are cop names (e.g., "Style/StringLiterals") and values are cop classes.
-
#docstring_for(cop_name) ⇒ Object
Returns the full YARD docstring for the given cop name.
-
#examples_for(cop_name) ⇒ Object
Returns an Array of Example objects for the given cop name.
-
#initialize(example_loader: ExampleLoader.instance) ⇒ CopCatalog
constructor
A new instance of CopCatalog.
-
#lookup(cop_name) ⇒ Object
Returns the cop class for the given name, or nil if not found.
Constructor Details
#initialize(example_loader: ExampleLoader.instance) ⇒ CopCatalog
Returns a new instance of CopCatalog.
16 17 18 19 20 |
# File 'lib/rubocounsel/cop_catalog.rb', line 16 def initialize(example_loader: ExampleLoader.instance) @example_loader = example_loader @cops = nil @examples_by_class_name = nil end |
Instance Method Details
#cops ⇒ Object
Returns a Hash where keys are cop names (e.g., "Style/StringLiterals") and values are cop classes.
24 25 26 |
# File 'lib/rubocounsel/cop_catalog.rb', line 24 def cops @cops ||= load_cops end |
#docstring_for(cop_name) ⇒ Object
Returns the full YARD docstring for the given cop name. Returns nil if no docstring found.
44 45 46 47 48 49 |
# File 'lib/rubocounsel/cop_catalog.rb', line 44 def docstring_for(cop_name) cop_class = lookup(cop_name) return nil unless cop_class docstrings_by_class_name[cop_class.to_s] end |
#examples_for(cop_name) ⇒ Object
Returns an Array of Example objects for the given cop name. Returns empty array if no examples found.
35 36 37 38 39 40 |
# File 'lib/rubocounsel/cop_catalog.rb', line 35 def examples_for(cop_name) cop_class = lookup(cop_name) return [] unless cop_class examples_by_class_name[cop_class.to_s] || [] end |
#lookup(cop_name) ⇒ Object
Returns the cop class for the given name, or nil if not found.
29 30 31 |
# File 'lib/rubocounsel/cop_catalog.rb', line 29 def lookup(cop_name) cops[cop_name] end |