Class: Tapioca::Helpers::Test::DslCompiler::CompilerContext
- Inherits:
-
Object
- Object
- Tapioca::Helpers::Test::DslCompiler::CompilerContext
- Extended by:
- T::Sig
- Includes:
- SorbetHelper
- Defined in:
- lib/tapioca/helpers/test/dsl_compiler.rb
Constant Summary
Constants included from SorbetHelper
SorbetHelper::FEATURE_REQUIREMENTS, SorbetHelper::SORBET_BIN, SorbetHelper::SORBET_EXE_PATH_ENV_VAR, SorbetHelper::SORBET_GEM_SPEC, SorbetHelper::SORBET_PAYLOAD_URL, SorbetHelper::SPOOM_CONTEXT
Instance Attribute Summary collapse
-
#compiler_class ⇒ Object
readonly
Returns the value of attribute compiler_class.
-
#other_compiler_classes ⇒ Object
readonly
Returns the value of attribute other_compiler_classes.
Instance Method Summary collapse
- #activate_other_dsl_compilers(compiler_classes) ⇒ Object
- #activated_compiler_classes ⇒ Object
- #errors ⇒ Object
- #gathered_constants ⇒ Object
-
#initialize(compiler_class) ⇒ CompilerContext
constructor
A new instance of CompilerContext.
- #rbi_for(constant_name, compiler_options: {}) ⇒ Object
Methods included from SorbetHelper
#sorbet, #sorbet_path, #sorbet_supports?
Constructor Details
#initialize(compiler_class) ⇒ CompilerContext
Returns a new instance of CompilerContext.
72 73 74 75 76 77 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 72 def initialize(compiler_class) @compiler_class = compiler_class @other_compiler_classes = T.let([], T::Array[T.class_of(Tapioca::Dsl::Compiler)]) @pipeline = T.let(nil, T.nilable(Tapioca::Dsl::Pipeline)) @errors = T.let([], T::Array[String]) end |
Instance Attribute Details
#compiler_class ⇒ Object (readonly)
Returns the value of attribute compiler_class.
66 67 68 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 66 def compiler_class @compiler_class end |
#other_compiler_classes ⇒ Object (readonly)
Returns the value of attribute other_compiler_classes.
69 70 71 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 69 def other_compiler_classes @other_compiler_classes end |
Instance Method Details
#activate_other_dsl_compilers(compiler_classes) ⇒ Object
80 81 82 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 80 def activate_other_dsl_compilers(compiler_classes) @other_compiler_classes = compiler_classes end |
#activated_compiler_classes ⇒ Object
85 86 87 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 85 def activated_compiler_classes [compiler_class, *other_compiler_classes] end |
#errors ⇒ Object
135 136 137 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 135 def errors pipeline.errors end |
#gathered_constants ⇒ Object
90 91 92 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 90 def gathered_constants compiler_class.processable_constants.filter_map(&:name).sort end |
#rbi_for(constant_name, compiler_options: {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 100 def rbi_for(constant_name, compiler_options: {}) # Make sure this is a constant that we can handle. unless gathered_constants.include?(constant_name.to_s) raise "`#{constant_name}` is not processable by the `#{compiler_class}` compiler." end file = RBI::File.new(strictness: "strong") constant = Object.const_get(constant_name) compiler = compiler_class.new(pipeline, file.root, constant, .transform_keys(&:to_s)) compiler.decorate rbi = Tapioca::DEFAULT_RBI_FORMATTER.print_file(file) result = sorbet( "--no-config", "--stop-after", "parser", "-e", "\"#{rbi}\"", ) unless result.status raise(SyntaxError, <<~MSG) Expected generated RBI file for `#{constant_name}` to not have any parsing errors. Got these parsing errors: #{result.err} MSG end rbi end |