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
-
#initialize(requested_constants:, requested_generators: [], error_handler: nil) ⇒ DslCompiler
constructor
A new instance of DslCompiler.
- #run(&blk) ⇒ Object
Constructor Details
#initialize(requested_constants:, requested_generators: [], error_handler: nil) ⇒ DslCompiler
Returns a new instance of DslCompiler.
27 28 29 30 31 32 33 34 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 27 def initialize(requested_constants:, requested_generators: [], error_handler: nil) @generators = T.let( gather_generators(requested_generators), T::Enumerable[Dsl::Base] ) @requested_constants = requested_constants @error_handler = T.let(error_handler || $stderr.method(:puts), T.proc.params(error: String).void) 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
#run(&blk) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tapioca/compilers/dsl_compiler.rb', line 37 def run(&blk) constants_to_process = gather_constants(requested_constants) 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 constants_to_process.sort_by { |c| c.name.to_s }.each do |constant| rbi = rbi_for_constant(constant) next if rbi.nil? blk.call(constant, rbi) end end |