Class: Tapioca::Dsl::Pipeline
- Inherits:
-
Object
- Object
- Tapioca::Dsl::Pipeline
- Defined in:
- lib/tapioca/dsl/pipeline.rb
Instance Attribute Summary collapse
-
#active_compilers ⇒ Object
readonly
: Enumerable.
-
#error_handler ⇒ Object
readonly
: ^(String error) -> void.
-
#errors ⇒ Object
readonly
: Array.
-
#requested_constants ⇒ Object
readonly
: Array[T::Module].
-
#requested_paths ⇒ Object
readonly
: Array.
-
#skipped_constants ⇒ Object
readonly
: Array[T::Module].
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
: ( | 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.
- #run(&blk) ⇒ Object
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 = @lsp_addon = lsp_addon @errors = [] #: Array[String] end |
Instance Attribute Details
#active_compilers ⇒ Object (readonly)
8 9 10 |
# File 'lib/tapioca/dsl/pipeline.rb', line 8 def active_compilers @active_compilers end |
#error_handler ⇒ Object (readonly)
: ^(String error) -> void
20 21 22 |
# File 'lib/tapioca/dsl/pipeline.rb', line 20 def error_handler @error_handler end |
#errors ⇒ Object (readonly)
: Array
23 24 25 |
# File 'lib/tapioca/dsl/pipeline.rb', line 23 def errors @errors end |
#requested_constants ⇒ Object (readonly)
: Array[T::Module]
11 12 13 |
# File 'lib/tapioca/dsl/pipeline.rb', line 11 def requested_constants @requested_constants end |
#requested_paths ⇒ Object (readonly)
: Array
14 15 16 |
# File 'lib/tapioca/dsl/pipeline.rb', line 14 def requested_paths @requested_paths end |
#skipped_constants ⇒ Object (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
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 |
#compilers ⇒ Object
: -> 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
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") |