Class: Tapioca::Dsl::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/tapioca/dsl/pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requested_constants:, requested_paths: [], requested_compilers: [], excluded_compilers: [], error_handler: $stderr.method(:puts).to_proc, skipped_constants: [], number_of_workers: nil, compiler_options: {}, lsp_addon: false) ⇒ Pipeline

: ( | requested_constants: Array[T::Module], | ?requested_paths: Array, | ?requested_compilers: Array, | ?excluded_compilers: Array, | ?error_handler: ^(String error) -> void, | ?skipped_constants: Array[T::Module], | ?number_of_workers: Integer?, | ?compiler_options: Hash[String, untyped], | ?lsp_addon: bool | ) -> void



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tapioca/dsl/pipeline.rb', line 36

def initialize(
  requested_constants:,
  requested_paths: [],
  requested_compilers: [],
  excluded_compilers: [],
  error_handler: $stderr.method(:puts).to_proc,
  skipped_constants: [],
  number_of_workers: nil,
  compiler_options: {},
  lsp_addon: false
)
  @active_compilers =
    gather_active_compilers(requested_compilers, excluded_compilers) #: Enumerable[singleton(Compiler)]
  @requested_constants = requested_constants
  @requested_paths = requested_paths
  @error_handler = error_handler
  @skipped_constants = skipped_constants
  @number_of_workers = number_of_workers
  @compiler_options = compiler_options
  @lsp_addon = lsp_addon
  @errors = [] #: Array[String]
end

Instance Attribute Details

#active_compilersObject (readonly)



8
9
10
# File 'lib/tapioca/dsl/pipeline.rb', line 8

def active_compilers
  @active_compilers
end

#error_handlerObject (readonly)

: ^(String error) -> void



20
21
22
# File 'lib/tapioca/dsl/pipeline.rb', line 20

def error_handler
  @error_handler
end

#errorsObject (readonly)

: Array



23
24
25
# File 'lib/tapioca/dsl/pipeline.rb', line 23

def errors
  @errors
end

#requested_constantsObject (readonly)

: Array[T::Module]



11
12
13
# File 'lib/tapioca/dsl/pipeline.rb', line 11

def requested_constants
  @requested_constants
end

#requested_pathsObject (readonly)

: Array



14
15
16
# File 'lib/tapioca/dsl/pipeline.rb', line 14

def requested_paths
  @requested_paths
end

#skipped_constantsObject (readonly)

: Array[T::Module]



17
18
19
# File 'lib/tapioca/dsl/pipeline.rb', line 17

def skipped_constants
  @skipped_constants
end

Instance Method Details

#add_error(error) ⇒ Object

: (String error) -> void



100
101
102
# File 'lib/tapioca/dsl/pipeline.rb', line 100

def add_error(error)
  @errors << error
end

#compiler_enabled?(compiler_name) ⇒ Boolean

: (String compiler_name) -> bool

Returns:

  • (Boolean)


105
106
107
108
109
110
111
# File 'lib/tapioca/dsl/pipeline.rb', line 105

def compiler_enabled?(compiler_name)
  potential_names = Compilers::NAMESPACES.map { |namespace| namespace + compiler_name }

  active_compilers.any? do |compiler|
    potential_names.any?(compiler.name)
  end
end

#compilersObject

: -> Array



114
115
116
117
118
# File 'lib/tapioca/dsl/pipeline.rb', line 114

def compilers
  @compilers ||= Runtime::Reflection.descendants_of(Compiler).sort_by do |compiler|
    T.must(compiler.name)
  end #: Array[singleton(Compiler)]?
end

#run(&blk) ⇒ Object

: [R] { (T::Module constant, RBI::File rbi) -> R } -> Array



60
61
62
63
64
65
66
67
68
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
# File 'lib/tapioca/dsl/pipeline.rb', line 60

def run(&blk)
  constants_to_process = gather_constants(requested_constants, requested_paths, skipped_constants)
    .select { |c| Module === c } # Filter value constants out
    .sort_by! { |c| T.must(Runtime::Reflection.name_of(c)) }

  # It's OK if there are no constants to process if we received a valid file/path.
  if constants_to_process.empty? && requested_paths.none? { |p| File.exist?(p) }
    report_error("      No classes/modules can be matched for RBI generation.\n      Please check that the requested classes/modules include processable DSL methods.\n    ERROR\n    raise Tapioca::Error, \"\"\n  end\n\n  if defined?(::ActiveRecord::Base) && constants_to_process.any? { |c| ::ActiveRecord::Base > c }\n    abort_if_pending_migrations!\n  end\n\n  result = Executor.new(\n    constants_to_process,\n    number_of_workers: @number_of_workers,\n  ).run_in_parallel do |constant|\n    rbi = rbi_for_constant(constant)\n    next if rbi.nil?\n\n    blk.call(constant, rbi)\n  end\n\n  if errors.any?\n    errors.each do |msg|\n      report_error(msg)\n    end\n\n    raise Tapioca::Error, \"\"\n  end\n\n  result.compact\nend\n")