From 4319721ce37946578b07491781666151bdb28274 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 27 Feb 2018 19:50:16 -0500 Subject: [PATCH] Add auto* flags to BuildContext --- angel_serialize_generator/lib/build_context.dart | 14 +++++++++----- angel_serialize_generator/lib/context.dart | 8 +++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/angel_serialize_generator/lib/build_context.dart b/angel_serialize_generator/lib/build_context.dart index 76ccabf4..49f17d73 100644 --- a/angel_serialize_generator/lib/build_context.dart +++ b/angel_serialize_generator/lib/build_context.dart @@ -25,9 +25,17 @@ Future buildContext( bool autoSnakeCaseNames, bool autoIdAndDateFields, {bool heedExclude: true}) async { + // Check for autoIdAndDateFields, autoSnakeCaseNames + autoIdAndDateFields = + annotation.peek('autoIdAndDateFields')?.boolValue ?? autoIdAndDateFields; + autoSnakeCaseNames = + annotation.peek('autoSnakeCaseNames')?.boolValue ?? autoSnakeCaseNames; + var ctx = new BuildContext(annotation, originalClassName: clazz.name, - sourceFilename: p.basename(buildStep.inputId.path)); + sourceFilename: p.basename(buildStep.inputId.path), + autoIdAndDateFields: autoIdAndDateFields, + autoSnakeCaseNames: autoSnakeCaseNames); var lib = await resolver.libraryFor(buildStep.inputId); List fieldNames = []; @@ -57,10 +65,6 @@ Future buildContext( } } - // Check for autoIdAndDateFields, autoSnakeCaseNames - autoIdAndDateFields = annotation.peek('autoIdAndDateFields')?.boolValue ?? autoIdAndDateFields; - autoSnakeCaseNames = annotation.peek('autoSnakeCaseNames')?.boolValue ?? autoSnakeCaseNames; - if (autoIdAndDateFields != false) { if (!fieldNames.contains('id')) { var idField = diff --git a/angel_serialize_generator/lib/context.dart b/angel_serialize_generator/lib/context.dart index afa9f5f6..6c1aab1f 100644 --- a/angel_serialize_generator/lib/context.dart +++ b/angel_serialize_generator/lib/context.dart @@ -18,6 +18,8 @@ class BuildContext { /// A map of "synthetic" fields, i.e. `id` and `created_at` injected automatically. final Map shimmed = {}; + final bool autoIdAndDateFields, autoSnakeCaseNames; + final String originalClassName, sourceFilename; /// The fields declared on the original class. @@ -28,7 +30,11 @@ class BuildContext { /// The name of the field that identifies data of this model type. String primaryKeyName = 'id'; - BuildContext(this.annotation, {this.originalClassName, this.sourceFilename}); + BuildContext(this.annotation, + {this.originalClassName, + this.sourceFilename, + this.autoSnakeCaseNames, + this.autoIdAndDateFields}); /// The name of the generated class. String get modelClassName => originalClassName.startsWith('_')