Module: Homebrew::Parlour

Defined in:
sorbet/parlour.rb

Overview

Parlour type signature generator helper class for Homebrew.

Constant Summary collapse

ROOT_DIR =
T.let(Pathname(__dir__).parent.realpath.freeze, Pathname).freeze

Class Method Summary collapse

Class Method Details

.ast_listArray<Parser::AST::Node>

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