Class: Tapioca::Compilers::EnvConfig

Inherits:
Dsl::Compiler
  • Object
show all
Defined in:
sorbet/tapioca/compilers/env_config.rb

Constant Summary collapse

ConstantType =
type_member { { fixed: Module } }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gather_constantsObject



16
# File 'sorbet/tapioca/compilers/env_config.rb', line 16

def self.gather_constants = [Homebrew::EnvConfig]

Instance Method Details

#decoratevoid

This method returns an undefined value.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'sorbet/tapioca/compilers/env_config.rb', line 19

def decorate
  root.create_module(T.must(constant.name)) do |mod|
    dynamic_methods = {}
    Homebrew::EnvConfig::ENVS.each do |env, hash|
      next if Homebrew::EnvConfig::CUSTOM_IMPLEMENTATIONS.include?(env)

      name = Homebrew::EnvConfig.env_method_name(env, hash)
      dynamic_methods[name] = hash[:default]
    end

    dynamic_methods.each do |method, default|
      return_type = if method.end_with?("?")
        T::Boolean
      elsif default
        default.class
      else
        T.nilable(String)
      end

      mod.create_method(method, return_type:, class_method: true)
    end
  end
end