Skip to content

Commit

Permalink
Allow parsing of files containing non-map yaml data. Issue stablekern…
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjackman committed Jan 21, 2021
1 parent a757a70 commit 4401d20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ abstract class Configuration {

/// [contents] must be YAML.
Configuration.fromString(String contents) {
final yamlMap = loadYaml(contents) as Map<dynamic, dynamic>;
final map =
yamlMap.map<String, dynamic>((k, v) => MapEntry(k.toString(), v));
decode(map);
dynamic yaml = loadYaml(contents);
if (yaml is Map) {
yaml = (yaml as Map<dynamic, dynamic>).map<String, dynamic>((k, v) => MapEntry(k.toString(), v));
}

decode(yaml);
}

/// Opens a file and reads its string contents into this instance's properties.
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ environment:
sdk: ">=2.0.0 <3.0.0"

dependencies:
analyzer: '>=0.37.0 <0.39.0'
yaml: '>=2.1.8 <3.0.0'
runtime: ^1.0.0-5

dev_dependencies:
test: ^1.3.0
test: ^1.3.0

0 comments on commit 4401d20

Please sign in to comment.