readConfig function

dynamic readConfig(
  1. String variable
)

Function used to read configuration variables from application config in memory.

This function is used when we inject a value via @Value(variable) where variable is the parameter.

Implementation

dynamic readConfig(String variable) {
  assert(variable.startsWith('@{') &&
      variable.endsWith('}') &&
      variable.length > 3);
  var varKey = variable.substring(2, variable.length - 1);
  var value = appConfig[varKey];

  /// String value can contains subvariable
  if (value != null && value is String) {
    var r = RegExp(r"(\@\{[\w\.]+\})");
    r.allMatches(value).map((e) => e.group(0)).toList().forEach((el) {
      value = value.replaceAll(el, readConfig(el!));
    });
  }
  return value;
}