write method

  1. @override
Class write()
override

Implementation

@override
Class write() {
  final databaseBuilderName = '\$${_databaseName}BuilderContract';

  final addMigrationsMethod = Method((builder) => builder
    ..name = 'addMigrations'
    ..returns = refer(databaseBuilderName)
    ..docs.add('/// Adds migrations to the builder.')
    ..requiredParameters.add(Parameter((builder) => builder
      ..name = 'migrations'
      ..type = refer('List<Migration>'))));

  final addCallbackMethod = Method((builder) => builder
    ..name = 'addCallback'
    ..returns = refer(databaseBuilderName)
    ..docs.add('/// Adds a database [Callback] to the builder.')
    ..requiredParameters.add(Parameter((builder) => builder
      ..name = 'callback'
      ..type = refer('Callback'))));

  final buildMethod = Method((builder) => builder
    ..returns = refer('Future<$_databaseName>')
    ..name = 'build'
    ..modifier = MethodModifier.async
    ..docs.add('/// Creates the database and initializes it.'));

  return Class((builder) => builder
    ..name = databaseBuilderName
    ..abstract = true
    ..methods.addAll([
      addMigrationsMethod,
      addCallbackMethod,
      buildMethod,
    ]));
}