Class: TypedConfig::Setup

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/typed_config/setup.rb

Instance Method Summary collapse

Constructor Details

#initialize(loader: Loader.new) ⇒ Setup

Returns a new instance of Setup.



13
14
15
# File 'lib/typed_config/setup.rb', line 13

def initialize(loader: Loader.new)
  @loader = loader
end

Instance Method Details

#call(config_path:, env: T.cast(ENV['RACK_ENV'], String)) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/typed_config/setup.rb', line 18

def call(config_path:, env: T.cast(ENV['RACK_ENV'], String))
  config_file = "#{config_path}/config.rb"
  return unless File.file?(config_file)

  require_relative config_file

  settings = build_settings(config_path: config_path, env: env)
  definition = TypeCoerce[Structs::Settings].new.from(settings)
  Object.const_set(Schema.schema_const_name, definition)
end