Class: Yard::Lint::Executor::InProcessRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/lint/executor/in_process_registry.rb

Overview

Manages shared YARD::Registry for in-process execution. Ensures files are parsed once and shared across all validators.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInProcessRegistry

Returns a new instance of InProcessRegistry.



15
16
17
18
19
# File 'lib/yard/lint/executor/in_process_registry.rb', line 15

def initialize
  @parsed = false
  @warnings = []
  @mutex = Mutex.new
end

Instance Attribute Details

#warningsArray<String> (readonly)

Returns warnings captured during parsing.

Returns:

  • (Array<String>)

    warnings captured during parsing



13
14
15
# File 'lib/yard/lint/executor/in_process_registry.rb', line 13

def warnings
  @warnings
end

Instance Method Details

#all_objectsArray<YARD::CodeObjects::Base>

Get all objects from the registry

Returns:

  • (Array<YARD::CodeObjects::Base>)


60
61
62
# File 'lib/yard/lint/executor/in_process_registry.rb', line 60

def all_objects
  YARD::Registry.all
end

#clear!void

This method returns an undefined value.

Clear the registry and reset state



103
104
105
106
107
108
109
# File 'lib/yard/lint/executor/in_process_registry.rb', line 103

def clear!
  @mutex.synchronize do
    YARD::Registry.clear
    @parsed = false
    @warnings = []
  end
end

#objects_for_validator(visibility:, file_excludes: [], file_selection: nil) ⇒ Array<YARD::CodeObjects::Base>

Get objects filtered for a specific validator

Parameters:

  • visibility (Symbol)

    visibility filter, either :all or :public

  • file_excludes (Array<String>) (defaults to: [])

    glob patterns for files to exclude

  • file_selection (Array<String>, nil) (defaults to: nil)

    specific files to include (nil = all files)

Returns:

  • (Array<YARD::CodeObjects::Base>)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/yard/lint/executor/in_process_registry.rb', line 69

def objects_for_validator(visibility:, file_excludes: [], file_selection: nil)
  objects = all_objects

  # Filter by visibility
  unless visibility == :all
    objects = objects.select do |obj|
      !obj.respond_to?(:visibility) || obj.visibility == :public
    end
  end

  # Filter by file selection (if provided)
  if file_selection && !file_selection.empty?
    expanded_selection = file_selection.to_set { |f| File.expand_path(f) }
    objects = objects.select do |obj|
      obj.file && expanded_selection.include?(File.expand_path(obj.file))
    end
  end

  # Filter by file excludes
  unless file_excludes.empty?
    objects = objects.reject do |obj|
      next false unless obj.file

      file_excludes.any? do |pattern|
        File.fnmatch(pattern, obj.file, File::FNM_PATHNAME | File::FNM_EXTGLOB)
      end
    end
  end

  objects
end

#parse(files) ⇒ void

This method returns an undefined value.

Parse Ruby source files and populate the YARD registry. Captures any warnings emitted by YARD during parsing for later dispatch.

Parameters:

  • files (Array<String>)

    absolute or relative paths to Ruby source files



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/yard/lint/executor/in_process_registry.rb', line 25

def parse(files)
  @mutex.synchronize do
    return if @parsed

    YARD::Registry.clear

    # Suppress YARD's default output by setting log level high
    # YARD uses its own logging levels, 4 is ERROR/FATAL level
    original_level = YARD::Logger.instance.level
    YARD::Logger.instance.level = 4 # Only show fatal errors

    # First pass: parse all files to process directive definitions
    YARD.parse(files)

    # Clear checksums to force reparsing without clearing the registry.
    # This allows macro definitions from the first pass to be available
    # during the second pass, enabling proper directive expansion regardless of parse order.
    YARD::Registry.checksums.clear

    # Second pass: reparse files now that all directive definitions are available
    @warnings = capture_warnings { YARD.parse(files) }
    @parsed = true

    YARD::Logger.instance.level = original_level
  end
end

#parsed?Boolean

Check if registry has been parsed

Returns:

  • (Boolean)


54
55
56
# File 'lib/yard/lint/executor/in_process_registry.rb', line 54

def parsed?
  @parsed
end