Class: Tapioca::Helpers::Test::DslCompiler::CompilerContext
- Inherits:
-
Object
- Object
- Tapioca::Helpers::Test::DslCompiler::CompilerContext
- 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
61 62 63 64 65 66 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 61 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)
55 56 57 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 55 def compiler_class @compiler_class end |
#other_compiler_classes ⇒ Object (readonly)
: Array
58 59 60 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 58 def other_compiler_classes @other_compiler_classes end |
Instance Method Details
#activate_other_dsl_compilers(compiler_classes) ⇒ Object
: (Array compiler_classes) -> void
69 70 71 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 69 def activate_other_dsl_compilers(compiler_classes) @other_compiler_classes = compiler_classes end |
#activated_compiler_classes ⇒ Object
: -> Array
74 75 76 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 74 def activated_compiler_classes [compiler_class, *other_compiler_classes] end |
#errors ⇒ Object
: -> Array
119 120 121 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 119 def errors pipeline.errors end |
#gathered_constants ⇒ Object
: -> Array
79 80 81 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 79 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
84 85 86 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 |
# File 'lib/tapioca/helpers/test/dsl_compiler.rb', line 84 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 |