Class: Tapioca::Compilers::Delegators Private

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

Overview

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

A compiler for subclasses of Delegator. To add a new delegator: require it above add add it to the DELEGATIONS hash below.

Constant Summary collapse

DELEGATIONS =

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.

Mapping of delegator classes to the classes they delegate to (as defined in __getobj__).

T.let({
  Cask::URL => Cask::URL::DSL,
}.freeze, T::Hash[Module, Module])
ConstantType =

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.

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:



19
# File 'sorbet/tapioca/compilers/delegators.rb', line 19

def self.gather_constants = DELEGATIONS.keys

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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'sorbet/tapioca/compilers/delegators.rb', line 22

def decorate
  root.create_path(constant) do |klass|
    # Note that `Delegtor` does not subclass `Object`:
    #   https://github.com/ruby/ruby/blob/a6383fb/lib/delegate.rb#L41
    # but we assume that we are delegating to a class that does.
    klass.create_include("Kernel")
    delegated = DELEGATIONS.fetch(constant)

    delegated.instance_methods(false).each do |method|
      signature = T::Utils.signature_for_method(delegated.instance_method(method))
      # TODO: handle methods with parameters
      return_type = signature&.return_type&.to_s || "T.untyped"
      klass.create_method(method.to_s, return_type:)
    end
  end
end