Module: Homebrew::Parlour Private

Defined in:
sorbet/parlour.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Parlour type signature generator helper class for Homebrew.

Constant Summary collapse

ROOT_DIR =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let(Pathname(T.must(__dir__)).parent.realpath.freeze, Pathname).freeze

Class Method Summary collapse

Class Method Details

.ast_listArray<Parser::AST::Node>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Array<Parser::AST::Node>)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'sorbet/parlour.rb', line 16

def self.ast_list
  @ast_list ||= begin
    ast_list = []
    parser = Parser::CurrentRuby.new
    prune_dirs = %w[sorbet shims test vendor].freeze

    ROOT_DIR.find do |path|
      Find.prune if path.directory? && prune_dirs.any? { |subdir| path == ROOT_DIR/subdir }

      Find.prune if path.file? && path.extname != ".rb"

      next unless path.file?

      buffer = Parser::Source::Buffer.new(path, source: path.read)

      parser.reset
      ast = parser.parse(buffer)
      ast_list << ast if ast
    end

    ast_list
  end
end