Class: Tapioca::Compilers::Forwardables

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

Constant Summary collapse

FORWARDABLE_FILENAME =
"forwardable.rb"
ARRAY_METHODS =
T.let(["to_a", "to_ary"].freeze, T::Array[String])
HASH_METHODS =
T.let(["to_h", "to_hash"].freeze, T::Array[String])
STRING_METHODS =
T.let(["to_s", "to_str", "to_json"].freeze, T::Array[String])
RETURN_TYPE_OVERRIDES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

Use this to override the default return type of a forwarded method:

T.let({
  "::Cask::Cask" => {
    "on_system_block_min_os" => "T.nilable(MacOSVersion)",
    "url"                    => "T.nilable(::Cask::URL)",
  },
}.freeze, T::Hash[String, T::Hash[String, String]])
ConstantType =
type_member { { fixed: Module } }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gather_constantsEnumerable<Module>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



26
27
28
29
30
31
# File 'sorbet/tapioca/compilers/forwardables.rb', line 26

def self.gather_constants
  Homebrew::Tapioca::Utils.named_objects_with_module(Forwardable).reject do |obj|
    # Avoid duplicate stubs for forwardables that are defined in vendored gems
    Object.const_source_location(T.must(obj.name))&.first&.include?("vendor/bundle/ruby")
  end
end

Instance Method Details

#decoratevoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



34
35
36
37
38
39
40
41
# File 'sorbet/tapioca/compilers/forwardables.rb', line 34

def decorate
  root.create_path(constant) do |klass|
    Homebrew::Tapioca::Utils.methods_from_file(constant, FORWARDABLE_FILENAME)
                            .each { |method| compile_forwardable_method(klass, method) }
    Homebrew::Tapioca::Utils.methods_from_file(constant, FORWARDABLE_FILENAME, class_methods: true)
                            .each { |method| compile_forwardable_method(klass, method, class_method: true) }
  end
end