fetchConfig method

Map<String, Object>? fetchConfig()

Fetches and maps configuration data from the sort_dependencies.yaml file.

Reads the configuration file line by line and converts valid entries into a map. Each line should follow the format key: value. Lines with invalid or missing keys are ignored.

  • Returns a Map of configuration entries where the keys are String and the values are either bool (if the value can be parsed as a boolean) or String.
  • Returns null if the configuration file cannot be read or contains no valid entries.

Implementation

Map<String, Object>? fetchConfig() {
  final configLines = _fetchConfigLines();
  if (configLines == null || configLines.isEmpty) return null;

  final mappedConfigEntries = configLines.map(
    (line) {
      final entry = _mapLineToEntry(line);

      return entry ?? MapEntry('', '');
    },
  ).toList()
    ..removeWhere((e) => e.key.isEmpty);

  return Map.fromEntries(mappedConfigEntries);
}