Class: Tapioca::Compilers::DslCompiler
- Inherits:
-
Object
- Object
- Tapioca::Compilers::DslCompiler
- Extended by:
- T::Sig
- Defined in:
- lib/tapioca/compilers/dsl_compiler.rb
Instance Attribute Summary collapse
-
#error_handler ⇒ Object
readonly
Returns the value of attribute error_handler.
-
#generators ⇒ Object
readonly
Returns the value of attribute generators.
-
#requested_constants ⇒ Object
readonly
Returns the value of attribute requested_constants.
Instance Method Summary collapse
- #generator_enabled?(generator_name) ⇒ Boolean
-
#initialize(requested_constants:, requested_generators: [], excluded_generators: [], error_handler: $stderr.method(:puts).to_proc, number_of_workers: nil) ⇒ DslCompiler
constructor
A new instance of DslCompiler.
- #run(&blk) ⇒ Object
Constructor Details
#initialize(requested_constants:, requested_generators: [], excluded_generators: [], error_handler: $stderr.method(:puts).to_proc, number_of_workers: nil) ⇒ DslCompiler
Returns a new instance of DslCompiler.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 29 def initialize( requested_constants:, requested_generators: [], excluded_generators: [], error_handler: $stderr.method(:puts).to_proc, number_of_workers: nil ) @generators = T.let( gather_generators(requested_generators, excluded_generators), T::Enumerable[Dsl::Base] ) @requested_constants = requested_constants @error_handler = error_handler @number_of_workers = number_of_workers end |
Instance Attribute Details
#error_handler ⇒ Object (readonly)
Returns the value of attribute error_handler.
18 19 20 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 18 def error_handler @error_handler end |
#generators ⇒ Object (readonly)
Returns the value of attribute generators.
12 13 14 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 12 def generators @generators end |
#requested_constants ⇒ Object (readonly)
Returns the value of attribute requested_constants.
15 16 17 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 15 def requested_constants @requested_constants end |
Instance Method Details
#generator_enabled?(generator_name) ⇒ Boolean
80 81 82 83 84 85 86 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 80 def generator_enabled?(generator_name) generator = Dsl::Base.resolve(generator_name) return false unless generator @generators.any?(generator) end |
#run(&blk) ⇒ Object
50 51 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 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 50 def run(&blk) constants_to_process = gather_constants(requested_constants) .select { |c| Reflection.name_of(c) && Module === c } # Filter anonymous or value constants .sort_by! { |c| T.must(Reflection.name_of(c)) } if constants_to_process.empty? 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 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 generators.flat_map(&:errors).each do |msg| report_error(msg) end result.compact end |