Add auto* flags to BuildContext

This commit is contained in:
Tobe O 2018-02-27 19:50:16 -05:00
parent 5ccc7755a7
commit 4319721ce3
2 changed files with 16 additions and 6 deletions

View file

@ -25,9 +25,17 @@ Future<BuildContext> buildContext(
bool autoSnakeCaseNames, bool autoSnakeCaseNames,
bool autoIdAndDateFields, bool autoIdAndDateFields,
{bool heedExclude: true}) async { {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, var ctx = new BuildContext(annotation,
originalClassName: clazz.name, 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); var lib = await resolver.libraryFor(buildStep.inputId);
List<String> fieldNames = []; List<String> fieldNames = [];
@ -57,10 +65,6 @@ Future<BuildContext> buildContext(
} }
} }
// Check for autoIdAndDateFields, autoSnakeCaseNames
autoIdAndDateFields = annotation.peek('autoIdAndDateFields')?.boolValue ?? autoIdAndDateFields;
autoSnakeCaseNames = annotation.peek('autoSnakeCaseNames')?.boolValue ?? autoSnakeCaseNames;
if (autoIdAndDateFields != false) { if (autoIdAndDateFields != false) {
if (!fieldNames.contains('id')) { if (!fieldNames.contains('id')) {
var idField = var idField =

View file

@ -18,6 +18,8 @@ class BuildContext {
/// A map of "synthetic" fields, i.e. `id` and `created_at` injected automatically. /// A map of "synthetic" fields, i.e. `id` and `created_at` injected automatically.
final Map<String, bool> shimmed = {}; final Map<String, bool> shimmed = {};
final bool autoIdAndDateFields, autoSnakeCaseNames;
final String originalClassName, sourceFilename; final String originalClassName, sourceFilename;
/// The fields declared on the original class. /// 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. /// The name of the field that identifies data of this model type.
String primaryKeyName = 'id'; 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. /// The name of the generated class.
String get modelClassName => originalClassName.startsWith('_') String get modelClassName => originalClassName.startsWith('_')