Line data Source code
1 : import 'package:enum_assist/src/configs/class_config.dart'; 2 : import 'package:enum_assist_annotation/enum_assist_annotation.dart'; 3 : 4 : /// {@template enum_assist.settings} 5 : /// Represents the settings to use when generating code. 6 : /// {@endtemplate} 7 : class Settings { 8 : /// {@macro enum_assist.settings} 9 0 : const Settings._(this._config); 10 : 11 : /// Resolve the settings from the build.yaml file. 12 : /// 13 : /// {@macro enum_assist.settings} 14 0 : factory Settings.resolve(Map<String, dynamic> json) { 15 : const createJsonConvKey = 'create_json_conv'; 16 : const serializedFormatKey = 'serialized_format'; 17 : const useDocCommentAsDescriptionKey = 'use_doc_comment_as_description'; 18 : 19 : const defaultVal = ClassConfig.defaults; 20 : 21 : final createJsonConvValue = 22 0 : json[createJsonConvKey] as bool? ?? defaultVal.createJsonConv; 23 : 24 0 : final serializedFormatString = json[serializedFormatKey] as String?; 25 : 26 : const serializedFormatConv = SerializedFormatConv(); 27 : final serializedFormatValue = serializedFormatString == null 28 0 : ? defaultVal.serializedFormat 29 0 : : serializedFormatConv.fromJson(serializedFormatString); 30 : 31 : final useDocCommentAsDescriptionValue = 32 0 : json[useDocCommentAsDescriptionKey] as bool? ?? 33 0 : defaultVal.useDocCommentAsDescription; 34 : 35 0 : final additionalExtensionsValue = defaultVal.additionalExtensions; 36 : 37 0 : final config = ClassConfig( 38 : createJsonConv: createJsonConvValue, 39 : serializedFormat: serializedFormatValue, 40 : useDocCommentAsDescription: useDocCommentAsDescriptionValue, 41 : additionalExtensions: additionalExtensionsValue, 42 : ); 43 0 : return Settings._(config); 44 : } 45 : 46 : final ClassConfig _config; 47 : 48 : /// {@macro enum_assist.settings} 49 0 : ClassConfig get config => _config; 50 : }