Config.fromJson constructor

Config.fromJson(
  1. Map<String, dynamic> jsonValue
)

Implementation

factory Config.fromJson(final Map<String, dynamic> jsonValue)
{
  var migrationsPath = _migrationsPath;
  final envs = <String, EnvConfig>{};
  for (final entry in jsonValue.entries) {
    if (entry.key == 'migrationsPath') {
      if (entry.value is! String) {
        throw const ConfigException('migrationsPath is expected to be a string.');
      }
      migrationsPath = entry.value;
      continue;
    }
    final env = entry.key;
    final jsonConnection = entry.value;
    if (jsonConnection is! Map<String, dynamic>) {
      throw ConfigException('$env is expected to be a valid object.');
    }
    envs[env] = EnvConfig.fromJson(jsonConnection);
  }
  return Config(
    envs: envs,
    migrationsPath: migrationsPath,
  );
}