asIterable method

Iterable<MapEntry<String, String>> asIterable({
  1. bool makePathsRelative = false,
})

Get the enumeration of key value pairs within the Configuration

If the makePathsRelative is true, the child keys returned will have the current configuration's Path trimmed from the front.

Implementation

Iterable<MapEntry<String, String>> asIterable({
  bool makePathsRelative = false,
}) sync* {
  var stack = QueueList<Configuration>()..addFirst(this);
  var rootSection =
      (this is ConfigurationSection) ? this as ConfigurationSection : null;
  var prefixLength = makePathsRelative && rootSection != null
      ? rootSection.path.length + 1
      : 0;

  while (stack.isNotEmpty) {
    var config = stack.removeFirst();
    if ((config is ConfigurationSection) &&
        (!makePathsRelative || (config != this))) {
      yield MapEntry<String, String>(
        config.path.substring(prefixLength),
        config.value ??= '',
        //config.value != null ? config.value as String : null,
      );
    }
    for (var child in config.getChildren()) {
      stack.addFirst(child);
    }
  }
}