routesFileMaker function

PartFile routesFileMaker(
  1. ServerServer server,
  2. String formatter(
    1. Spec
    )
)

Implementation

PartFile routesFileMaker(ServerServer server, String Function(Spec) formatter) {
  final routes = Method(
    (p) => p
      ..name = 'routes'
      ..lambda = true
      ..requiredParameters.add(
        Parameter(
          (p) => p
            ..name = 'di'
            ..type = refer((DI).name),
        ),
      )
      ..returns = TypeReference(
        (b) => b
          ..symbol = 'List'
          ..types.add(refer((Route).name)),
      )
      ..body = Block.of([
        literalList([
          for (final route in server.routes) createParentRef(route),
        ]).statement,
      ]),
  );

  final content = formatter(routes);

  return PartFile(
    path: ['definitions', '__routes'],
    content: content,
  );
}