Class: Tapioca::Dsl::Compilers::PhlexSorbet
- Inherits:
-
Compiler
- Object
- Compiler
- Tapioca::Dsl::Compilers::PhlexSorbet
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/tapioca/dsl/compilers/phlex_sorbet.rb
Overview
Generates RBI files for Phlex::Sorbet components.
This compiler generates:
-
A typed ‘props` accessor returning the component’s ‘Props` struct
-
A typed ‘initialize` signature derived from the component’s ‘Props` struct
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.gather_constants ⇒ Object
30 31 32 33 34 |
# File 'lib/tapioca/dsl/compilers/phlex_sorbet.rb', line 30 def self.gather_constants all_classes.select do |c| c.is_a?(Class) && c.included_modules.include?(::Phlex::Sorbet) end end |
.params_for(props_class) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tapioca/dsl/compilers/phlex_sorbet.rb', line 40 def self.params_for(props_class) return [] unless props_class props_class.props.map do |field_name, prop_info| type = prop_info[:type_object].to_s has_default = prop_info.key?(:default) param = if has_default RBI::KwOptParam.new(field_name.to_s, "T.unsafe(nil)") else RBI::KwParam.new(field_name.to_s) end RBI::TypedParam.new(param: param, type: type) end end |
Instance Method Details
#decorate ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/tapioca/dsl/compilers/phlex_sorbet.rb', line 21 def decorate root.create_path(constant) do |klass| generate_props_method(klass) if props_class generate_new_method(klass) generate_initialize_method(klass) end end |