Class: Tapioca::Dsl::Pipeline
- Inherits:
-
Object
- Object
- Tapioca::Dsl::Pipeline
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/dsl/pipeline.rb
Instance Attribute Summary collapse
- #active_compilers ⇒ Object readonly
-
#error_handler ⇒ Object
readonly
: ^(String error) -> void.
-
#errors ⇒ Object
readonly
: Array.
-
#requested_constants ⇒ Object
readonly
: Array.
-
#requested_paths ⇒ Object
readonly
: Array.
-
#skipped_constants ⇒ Object
readonly
: Array.
Instance Method Summary collapse
-
#add_error(error) ⇒ Object
: (String error) -> void.
-
#compiler_enabled?(compiler_name) ⇒ Boolean
: (String compiler_name) -> bool.
-
#compilers ⇒ Object
: -> Array.
- #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 constructor
-
#run(&blk) ⇒ Object
: [T] { (Module constant, RBI::File rbi) -> T } -> Array.
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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tapioca/dsl/pipeline.rb', line 28 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 = @lsp_addon = lsp_addon @errors = [] #: Array[String] end |
Instance Attribute Details
#active_compilers ⇒ Object (readonly)
10 11 12 |
# File 'lib/tapioca/dsl/pipeline.rb', line 10 def active_compilers @active_compilers end |
#error_handler ⇒ Object (readonly)
: ^(String error) -> void
22 23 24 |
# File 'lib/tapioca/dsl/pipeline.rb', line 22 def error_handler @error_handler end |
#errors ⇒ Object (readonly)
: Array
25 26 27 |
# File 'lib/tapioca/dsl/pipeline.rb', line 25 def errors @errors end |
#requested_constants ⇒ Object (readonly)
: Array
13 14 15 |
# File 'lib/tapioca/dsl/pipeline.rb', line 13 def requested_constants @requested_constants end |
#requested_paths ⇒ Object (readonly)
: Array
16 17 18 |
# File 'lib/tapioca/dsl/pipeline.rb', line 16 def requested_paths @requested_paths end |
#skipped_constants ⇒ Object (readonly)
: Array
19 20 21 |
# File 'lib/tapioca/dsl/pipeline.rb', line 19 def skipped_constants @skipped_constants end |
Instance Method Details
#add_error(error) ⇒ Object
: (String error) -> void
92 93 94 |
# File 'lib/tapioca/dsl/pipeline.rb', line 92 def add_error(error) @errors << error end |
#compiler_enabled?(compiler_name) ⇒ Boolean
: (String compiler_name) -> bool
97 98 99 100 101 102 103 |
# File 'lib/tapioca/dsl/pipeline.rb', line 97 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 |
#compilers ⇒ Object
: -> Array
106 107 108 109 110 |
# File 'lib/tapioca/dsl/pipeline.rb', line 106 def compilers @compilers ||= Runtime::Reflection.descendants_of(Compiler).sort_by do |compiler| T.must(compiler.name) end #: Array[singleton(Compiler)]? end |
#run(&blk) ⇒ Object
: [T] { (Module constant, RBI::File rbi) -> T } -> Array
52 53 54 55 56 57 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 87 88 89 |
# File 'lib/tapioca/dsl/pipeline.rb', line 52 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") |