Class: RuboCounsel::ExampleLoader

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

Overview

Loads @example tags from RuboCop source files using YARD. Returns examples grouped by cop class name.

This is isolated from cop discovery - if YARD parsing fails, the rest of RuboCounsel can still function (just without examples).

Uses singleton pattern to avoid re-parsing YARD on every CopCatalog instantiation.

Constant Summary collapse

COP_BASE_CLASS =
"RuboCop::Cop::Base"
EXCLUDED_BASE_CLASSES =
[COP_BASE_CLASS, "RuboCop::Cop::Cop"].freeze
EXCLUDED_COP_NAMESPACES =

InternalAffairs cops are for RuboCop development, not end users. We exclude them since they won't be relevant for linting application code.

["InternalAffairs"].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExampleLoader

Returns a new instance of ExampleLoader.



33
34
35
36
# File 'lib/rubocounsel/example_loader.rb', line 33

def initialize
  @examples = nil
  @docstrings = nil
end

Class Method Details

.instanceObject



24
25
26
# File 'lib/rubocounsel/example_loader.rb', line 24

def instance
  @instance ||= new
end

.reset!Object



28
29
30
# File 'lib/rubocounsel/example_loader.rb', line 28

def reset!
  @instance = nil
end

Instance Method Details

#docstringsObject

Returns a Hash where keys are cop class names and values are the full YARD docstrings.



46
47
48
49
# File 'lib/rubocounsel/example_loader.rb', line 46

def docstrings
  load_all unless @docstrings
  @docstrings
end

#examplesObject

Returns a Hash where keys are cop class names (e.g., "RuboCop::Cop::Style::StringLiterals") and values are Arrays of Example objects.



40
41
42
43
# File 'lib/rubocounsel/example_loader.rb', line 40

def examples
  load_all unless @examples
  @examples
end

#loadObject

Legacy method for backwards compatibility



52
53
54
# File 'lib/rubocounsel/example_loader.rb', line 52

def load
  examples
end