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>)


74
75
76
# File 'lib/yard/lint/executor/in_process_registry.rb', line 74

def all_objects
  YARD::Registry.all
end

#clear!void

This method returns an undefined value.

Clear the registry and reset state



117
118
119
120
121
122
123
# File 'lib/yard/lint/executor/in_process_registry.rb', line 117

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>)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/yard/lint/executor/in_process_registry.rb', line 83

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, source: nil) ⇒ 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

  • source (String, nil) (defaults to: nil)

    in-memory source; when given, ‘files.first` is used as the virtual filename for registry/location reporting only



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/yard/lint/executor/in_process_registry.rb', line 27

def parse(files, source: nil)
  @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

    if source
      virtual_path = files.first
      # First pass: register directive/macro definitions from the in-memory source.
      # We set parser.file manually so registered objects carry the virtual path.
      parse_source_string(source, virtual_path)
      # Clear checksums so the second pass is not skipped
      YARD::Registry.checksums.clear
      # Second pass: full parse with all directives available
      @warnings = capture_warnings { parse_source_string(source, virtual_path) }
    else
      # 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) }
    end

    @parsed = true

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

#parsed?Boolean

Check if registry has been parsed

Returns:

  • (Boolean)


68
69
70
# File 'lib/yard/lint/executor/in_process_registry.rb', line 68

def parsed?
  @parsed
end