MemoryConfig.fromYaml constructor

MemoryConfig.fromYaml(
  1. Object? node
)

Parses the section strictly: a non-map node, unknown keys, and non-string values throw ConfigException (a typo must surface, not silently write memory somewhere unexpected).

Implementation

factory MemoryConfig.fromYaml(Object? node) {
  if (node is! Map) {
    throw const ConfigException(
      'memory: section must be a map (projectPath/userPath)',
    );
  }
  String? projectPath;
  String? userPath;
  for (final entry in node.entries) {
    final key = '${entry.key}';
    final value = entry.value;
    if (value is! String) {
      throw ConfigException('memory.$key must be a string path');
    }
    switch (key) {
      case 'projectPath':
        projectPath = value;
      case 'userPath':
        userPath = value;
      default:
        throw ConfigException(
          'memory: unknown key "$key" (known: projectPath, userPath)',
        );
    }
  }
  return MemoryConfig(projectPath: projectPath, userPath: userPath);
}