Module net.morimekta.tiny.server
Package net.morimekta.tiny.server.config
Class ConfigSupplier<ConfigType>
- java.lang.Object
-
- net.morimekta.tiny.server.config.ConfigSupplier<ConfigType>
-
- Type Parameters:
ConfigType- The config type.
- All Implemented Interfaces:
Supplier<ConfigType>
public class ConfigSupplier<ConfigType> extends Object implements Supplier<ConfigType>
A wrapper around a config file to handle loading and parsing during application setup.class MyApplication extends TinyApplication { private var config = ConfigSupplier.yamlConfig(MyConfig.class) {@literal@}Override public void initialize(ArgParser argParser, TinyApplicationContext.Builder context) { argParser.add(Option .optionLong("--config", "A config file", ValueParser.path(config::loadFromFile)) .required()) } public void onStart(TinyApplicationContext context) { var myConfig = config.get(); // you have a config! } }
-
-
Constructor Summary
Constructors Constructor Description ConfigSupplier(ConfigReader<ConfigType> loader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigTypeget()voidload(Path filePath)voidloadUnchecked(Path filePath)static <ConfigType>
ConfigSupplier<ConfigType>yamlConfig(Class<ConfigType> type)static <ConfigType>
ConfigSupplier<ConfigType>yamlConfig(Class<ConfigType> type, Consumer<com.fasterxml.jackson.databind.ObjectMapper> initMapper)
-
-
-
Constructor Detail
-
ConfigSupplier
public ConfigSupplier(ConfigReader<ConfigType> loader)
-
-
Method Detail
-
loadUnchecked
public void loadUnchecked(Path filePath)
-
load
public void load(Path filePath) throws IOException
- Throws:
IOException
-
get
public ConfigType get()
- Specified by:
getin interfaceSupplier<ConfigType>
-
yamlConfig
public static <ConfigType> ConfigSupplier<ConfigType> yamlConfig(Class<ConfigType> type)
-
yamlConfig
public static <ConfigType> ConfigSupplier<ConfigType> yamlConfig(Class<ConfigType> type, Consumer<com.fasterxml.jackson.databind.ObjectMapper> initMapper)
-
-