Subclasses may override this method to read from something that is not a Map.
Sometimes a configuration value can be represented in multiple ways. For example, a DatabaseConnectionConfiguration
can be a Map
of each component or a single URI String
that can be decomposed into each component. Subclasses may override
this method to provide this type of behavior. This method is executed when an instance of ConfigurationItem
is ready to be parsed,
but the value from the YAML is not a Map
. By default, this method throws an exception.
Source
void decode(dynamic anything) { if (anything is! String) { throw new ConfigurationException("Invalid decode value for ${this.runtimeType}, expected String, got ${anything.runtimeType}."); } var uri = Uri.parse(anything); host = uri.host; port = uri.port; if (uri.pathSegments.length == 1) { databaseName = uri.pathSegments.first; } if (uri.userInfo == null || uri.userInfo == '') { return; } var authority = uri.userInfo.split(":"); if (authority != null) { if (authority.length > 0) { username = authority.first; } if (authority.length > 1) { password = authority.last; } } }