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
: singleton(Tapioca::Dsl::Compiler).
-
#other_compiler_classes ⇒ Object
readonly
: Array.
Instance Method Summary collapse
-
#activate_other_dsl_compilers(compiler_classes) ⇒ Object
: (Array compiler_classes) -> void.
-
#activated_compiler_classes ⇒ Object
: -> Array.
-
#errors ⇒ Object
: -> Array.
-
#gathered_constants ⇒ Object
: -> Array.
-
#initialize(compiler_class) ⇒ CompilerContext
constructor
: (singleton(Tapioca::Dsl::Compiler) compiler_class) -> void.
-
#rbi_for(constant_name, compiler_options: {}) ⇒ Object
: ((Symbol | String) constant_name, ?compiler_options: Hash[Symbol, untyped]) -> String.
Methods included from SorbetHelper
#sorbet, #sorbet_path, #sorbet_supports?
Constructor Details
#initialize(compiler_class) ⇒ CompilerContext
: (singleton(Tapioca::Dsl::Compiler) compiler_class) -> void
64 65 66 67 68 69 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 64 def initialize(compiler_class) @compiler_class = compiler_class @other_compiler_classes = [] #: Array[singleton(Tapioca::Dsl::Compiler)] @pipeline = nil #: Tapioca::Dsl::Pipeline? @errors = [] #: Array[String] end |
Instance Attribute Details
#compiler_class ⇒ Object (readonly)
: singleton(Tapioca::Dsl::Compiler)
58 59 60 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 58 def compiler_class @compiler_class end |
#other_compiler_classes ⇒ Object (readonly)
: Array
61 62 63 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 61 def other_compiler_classes @other_compiler_classes end |
Instance Method Details
#activate_other_dsl_compilers(compiler_classes) ⇒ Object
: (Array compiler_classes) -> void
72 73 74 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 72 def activate_other_dsl_compilers(compiler_classes) @other_compiler_classes = compiler_classes end |
#activated_compiler_classes ⇒ Object
: -> Array
77 78 79 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 77 def activated_compiler_classes [compiler_class, *other_compiler_classes] end |
#errors ⇒ Object
: -> Array
122 123 124 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 122 def errors pipeline.errors end |
#gathered_constants ⇒ Object
: -> Array
82 83 84 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 82 def gathered_constants compiler_class.processable_constants.filter_map(&:name).sort end |
#rbi_for(constant_name, compiler_options: {}) ⇒ Object
: ((Symbol | String) constant_name, ?compiler_options: Hash[Symbol, untyped]) -> String
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 87 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, " Expected generated RBI file for `\#{constant_name}` to not have any parsing errors.\n\n Got these parsing errors:\n\n \#{result.err}\n MSG\n end\n\n rbi\nend\n") |