class Tapioca::Dsl::Compilers::Config
“‘
end
def github=(value); end
sig { params(value: T.untyped).returns(T.untyped) }
def github; end
sig { returns(T.untyped) }
class AppSettingsConfigOptions < ::Config::Options
AppSettings = T.let(T.unsafe(nil), AppSettingsConfigOptions)
“`rbi
this compiler will produce the following RBI file:
“`
end
config.const_name = “AppSettings”
Config.setup do |config|
“`ruby
and a `Config` setup like:
“`
client_secret: super_secret
client_id: 54321
token: 12345
github:
—
“`yaml
For a setting file like the following:
config values.
by default `Settings`. Application code uses methods on this constant to read off
env variables. It then assigns this instance to a constant with a configurable name,
The gem creates a `Config::Options` instance based on the settings files and/or<br><br>(github.com/rubyconfig/config) gem.
`Tapioca::Dsl::Compilers::Config` generates RBI files for classes generated by the
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
def gather_constants
def gather_constants name = ::Config.const_name return [] unless Object.const_defined?(name) config_object = Object.const_get(name) options_class_name = "#{name}#{CONFIG_OPTIONS_SUFFIX}" Object.const_set(options_class_name, config_object.singleton_class) Array(config_object.singleton_class) end