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
Returns the value of attribute active_compilers.
-
#error_handler ⇒ Object
readonly
Returns the value of attribute error_handler.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#requested_constants ⇒ Object
readonly
Returns the value of attribute requested_constants.
-
#requested_paths ⇒ Object
readonly
Returns the value of attribute requested_paths.
-
#skipped_constants ⇒ Object
readonly
Returns the value of attribute skipped_constants.
Instance Method Summary collapse
- #add_error(error) ⇒ Object
- #compiler_enabled?(compiler_name) ⇒ Boolean
- #compilers ⇒ Object
-
#initialize(requested_constants:, requested_paths: [], requested_compilers: [], excluded_compilers: [], error_handler: $stderr.method(:puts).to_proc, skipped_constants: [], number_of_workers: nil, compiler_options: {}) ⇒ Pipeline
constructor
A new instance of Pipeline.
- #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: {}) ⇒ Pipeline
Returns a new instance of Pipeline.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tapioca/dsl/pipeline.rb', line 39 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: {} ) @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 @skipped_constants = skipped_constants @number_of_workers = number_of_workers @compiler_options = @errors = T.let([], T::Array[String]) end |
Instance Attribute Details
#active_compilers ⇒ Object (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_handler ⇒ Object (readonly)
Returns the value of attribute error_handler.
22 23 24 |
# File 'lib/tapioca/dsl/pipeline.rb', line 22 def error_handler @error_handler end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
25 26 27 |
# File 'lib/tapioca/dsl/pipeline.rb', line 25 def errors @errors end |
#requested_constants ⇒ Object (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_paths ⇒ Object (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 |
#skipped_constants ⇒ Object (readonly)
Returns the value of attribute skipped_constants.
19 20 21 |
# File 'lib/tapioca/dsl/pipeline.rb', line 19 def skipped_constants @skipped_constants end |
Instance Method Details
#add_error(error) ⇒ Object
102 103 104 |
# File 'lib/tapioca/dsl/pipeline.rb', line 102 def add_error(error) @errors << error end |
#compiler_enabled?(compiler_name) ⇒ Boolean
107 108 109 110 111 112 113 |
# File 'lib/tapioca/dsl/pipeline.rb', line 107 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
116 117 118 119 120 121 122 123 |
# File 'lib/tapioca/dsl/pipeline.rb', line 116 def compilers @compilers ||= T.let( Runtime::Reflection.descendants_of(Compiler).sort_by do |compiler| T.must(compiler.name) end, T.nilable(T::Array[T.class_of(Compiler)]), ) end |
#run(&blk) ⇒ Object
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 98 99 |
# File 'lib/tapioca/dsl/pipeline.rb', line 67 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(<<~ERROR) No classes/modules can be matched for RBI generation. Please check that the requested classes/modules include processable DSL methods. ERROR end if defined?(::ActiveRecord::Base) && constants_to_process.any? { |c| ::ActiveRecord::Base > c } abort_if_pending_migrations! end result = Executor.new( constants_to_process, number_of_workers: @number_of_workers, ).run_in_parallel do |constant| rbi = rbi_for_constant(constant) next if rbi.nil? blk.call(constant, rbi) end errors.each do |msg| report_error(msg) end result.compact end |