Class: Tapioca::Dsl::Pipeline

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
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, number_of_workers: nil) ⇒ Pipeline

Returns a new instance of Pipeline.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tapioca/dsl/pipeline.rb', line 34

def initialize(
  requested_constants:,
  requested_paths: [],
  requested_compilers: [],
  excluded_compilers: [],
  error_handler: $stderr.method(:puts).to_proc,
  number_of_workers: nil
)
  @active_compilers = T.let(
    gather_active_compilers(requested_compilers, excluded_compilers),
    T::Enumerable[T.class_of(Compiler)],
  )
  @requested_constants = requested_constants
  @requested_paths = requested_paths
  @error_handler = error_handler
  @number_of_workers = number_of_workers
  @errors = T.let([], T::Array[String])
end

Instance Attribute Details

#active_compilersObject (readonly)

Returns the value of attribute active_compilers.



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

def active_compilers
  @active_compilers
end

#error_handlerObject (readonly)

Returns the value of attribute error_handler.



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

def error_handler
  @error_handler
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#requested_constantsObject (readonly)

Returns the value of attribute requested_constants.



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

def requested_constants
  @requested_constants
end

#requested_pathsObject (readonly)

Returns the value of attribute requested_paths.



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

def requested_paths
  @requested_paths
end

Instance Method Details

#add_error(error) ⇒ Object



89
90
91
# File 'lib/tapioca/dsl/pipeline.rb', line 89

def add_error(error)
  @errors << error
end

#compiler_enabled?(compiler_name) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
# File 'lib/tapioca/dsl/pipeline.rb', line 94

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



103
104
105
106
107
108
# File 'lib/tapioca/dsl/pipeline.rb', line 103

def compilers
  @compilers = T.let(@compilers, T.nilable(T::Array[T.class_of(Compiler)]))
  @compilers ||= Runtime::Reflection.descendants_of(Compiler).sort_by do |compiler|
    T.must(compiler.name)
  end
end

#run(&blk) ⇒ Object



58
59
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
# File 'lib/tapioca/dsl/pipeline.rb', line 58

def run(&blk)
  constants_to_process = gather_constants(requested_constants, requested_paths)
    .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.select { |p| File.exist?(p) }.empty?
    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  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  errors.each do |msg|\n    report_error(msg)\n  end\n\n  result.compact\nend\n")