import 'package:brick_generator/models/brick_variable.dart'; import 'package:yaml/yaml.dart'; const _brickNameKey = 'brick_name'; const _pathToBrickifyKey = 'path_to_brickify'; const _variablesKey = 'variables'; class BrickConfig { String? brickName; String? pathToBrickify; List? variables; BrickConfig({ required this.brickName, required this.pathToBrickify, required this.variables, }); BrickConfig._(); factory BrickConfig.parser() => BrickConfig._(); static BrickConfig? from(YamlMap? data) => data != null ? BrickConfig( brickName: data[_brickNameKey] as String?, pathToBrickify: data[_pathToBrickifyKey] as String?, variables: (data[_variablesKey] as YamlMap?) ?.map( (dynamic key, dynamic value) => MapEntry( key, BrickVariable.from(value as YamlMap?), ), ) .values .toList(), ) : null; void checkFormat() { if (brickName == null || pathToBrickify == null) { throw ArgumentError( 'Yaml file is not conform', ); } if (variables != null) { for (final variable in variables!) { variable?.checkFormat(); } } } }