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
67 68 69 70 71 72 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 67 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)
61 62 63 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 61 def compiler_class @compiler_class end |
#other_compiler_classes ⇒ Object (readonly)
: Array
64 65 66 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 64 def other_compiler_classes @other_compiler_classes end |
Instance Method Details
#activate_other_dsl_compilers(compiler_classes) ⇒ Object
: (Array compiler_classes) -> void
75 76 77 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 75 def activate_other_dsl_compilers(compiler_classes) @other_compiler_classes = compiler_classes end |
#activated_compiler_classes ⇒ Object
: -> Array
80 81 82 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 80 def activated_compiler_classes [compiler_class, *other_compiler_classes] end |
#errors ⇒ Object
: -> Array
125 126 127 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 125 def errors pipeline.errors end |
#gathered_constants ⇒ Object
: -> Array
85 86 87 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 85 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
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 120 121 122 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 90 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") |