Class: Tapioca::Compilers::ApiStructs

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

Constant Summary collapse

ConstantType =
type_member { { fixed: T.class_of(T::Struct) } }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gather_constantsEnumerable<T::Module[T.anything]>

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:



14
# File 'sorbet/tapioca/compilers/api_structs.rb', line 14

def self.gather_constants = [::Homebrew::API::FormulaStruct, ::Homebrew::API::CaskStruct]

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.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'sorbet/tapioca/compilers/api_structs.rb', line 17

def decorate
  class_name = constant.name
  raise ArgumentError, "Cannot generate RBI for anonymous struct #{constant.inspect}" if class_name.nil?

  root.create_class(class_name) do |klass|
    # `constant` is one of the gathered structs, resolved at runtime.
    # rubocop:disable Sorbet/ConstantsFromStrings
    constant.const_get(:PREDICATES).each do |predicate_name|
      klass.create_method("#{predicate_name}?", return_type: "T::Boolean")
    end
    # rubocop:enable Sorbet/ConstantsFromStrings
  end
end