Class: Tapioca::Dsl::Compilers::SorbetTypedPropsConstructor

Inherits:
Tapioca::Dsl::Compiler
  • Object
show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/tapioca/dsl/compilers/sorbet_typed_props_constructor.rb,
lib/tapioca/dsl/compilers/sorbet_typed_props_constructor/prop_to_param_converter.rb

Overview

tapioca compiler generating rbi containing the initializer interface for a class using sorbet SorbetTyped::Props

Defined Under Namespace

Classes: PropToParamConverter

Constant Summary collapse

ConstantType =
type_member { { upper: T::Class[SorbetTyped::Props] } }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.gather_constantsObject



17
18
19
20
# File 'lib/tapioca/dsl/compilers/sorbet_typed_props_constructor.rb', line 17

def self.gather_constants
  # Collect all the classes that include SorbetTyped::Props
  all_classes.select { |klass| klass < SorbetTyped::Props }
end

Instance Method Details

#decorateObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/tapioca/dsl/compilers/sorbet_typed_props_constructor.rb', line 23

def decorate
  # NOTE: skip RBI generation for abstract classes, as they cannot be instantiated anyways
  return if T::AbstractUtils.abstract_module?(constant)
  # NOTE: do not generate a new initializer signature, if the class sets
  # its own and doesn't use the prop generated one.
  return if constant.private_instance_methods(false).include?(:initialize)
  return if props.empty?

  define_initializer_sig
end