class Tapioca::Dsl::Compilers::Config
def decorate
def decorate # The constant we are given is the specialized config options type option_class_name = constant.name return unless option_class_name # Grab the config constant name and the actual config constant config_constant_name = option_class_name .gsub(/#{CONFIG_OPTIONS_SUFFIX}$/, "") config_constant = Object.const_get(config_constant_name) # Look up method names from the keys of the config constant method_names = config_constant.keys return if method_names.empty? root.create_constant(config_constant_name, value: "T.let(T.unsafe(nil), #{option_class_name})") root.create_class(option_class_name, superclass_name: "::Config::Options") do |mod| # We need this to be generic only because `Config::Options` is an # enumerable and, thus, needs to redeclare the `Elem` type member. # # We declare it as a fixed member of `T.untyped` so that if anyone # enumerates the entries, we don't make any assumptions about their # types. mod.create_extend("T::Generic") mod.create_type_variable("Elem", type: "type_member", fixed: "T.untyped") method_names.each do |method_name| # Create getter method mod.create_method( method_name.to_s, return_type: "T.untyped", ) # Create setter method mod.create_method( "#{method_name}=", parameters: [create_param("value", type: "T.untyped")], return_type: "T.untyped", ) end end end