More flexibility for service gen
This commit is contained in:
parent
29252ee915
commit
5e5d617703
7 changed files with 45 additions and 26 deletions
|
@ -85,7 +85,7 @@ class ServiceCommand extends Command {
|
|||
|
||||
configureServer.body = new Block((block) {
|
||||
generator.applyToConfigureServer(
|
||||
configureServer, block, name, rc.snakeCase);
|
||||
serviceLib, configureServer, block, name, rc.snakeCase);
|
||||
|
||||
// return (Angel app) async {}
|
||||
var closure = new Method((closure) {
|
||||
|
@ -95,11 +95,11 @@ class ServiceCommand extends Command {
|
|||
..name = 'app'
|
||||
..type = refer('Angel')));
|
||||
closure.body = new Block((block) {
|
||||
generator.beforeService(block, name, rc.snakeCase);
|
||||
generator.beforeService(serviceLib, block, name, rc.snakeCase);
|
||||
|
||||
// app.use('/api/todos', new MapService());
|
||||
var service =
|
||||
generator.createInstance(closure, name, rc.snakeCase);
|
||||
var service = generator.createInstance(
|
||||
serviceLib, closure, name, rc.snakeCase);
|
||||
|
||||
if (argResults['typed'] as bool) {
|
||||
var tb = new TypeReference((b) => b
|
||||
|
|
|
@ -20,8 +20,8 @@ class CustomServiceGenerator extends ServiceGenerator {
|
|||
}
|
||||
|
||||
@override
|
||||
Expression createInstance(
|
||||
MethodBuilder methodBuilder, String name, String lower) {
|
||||
Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder,
|
||||
String name, String lower) {
|
||||
return refer('${name}Service').newInstance([]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,12 @@ class FileServiceGenerator extends ServiceGenerator {
|
|||
bool get goesFirst => true;
|
||||
|
||||
@override
|
||||
void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block,
|
||||
String name, String lower) {
|
||||
void applyToConfigureServer(
|
||||
LibraryBuilder library,
|
||||
MethodBuilder configureServer,
|
||||
BlockBuilder block,
|
||||
String name,
|
||||
String lower) {
|
||||
configureServer.requiredParameters.add(new Parameter((b) => b
|
||||
..name = 'dbDirectory'
|
||||
..type = refer('Directory')));
|
||||
|
@ -26,13 +30,15 @@ class FileServiceGenerator extends ServiceGenerator {
|
|||
library.directives.addAll([
|
||||
new Directive.import(
|
||||
'package:angel_file_service/angel_file_service.dart'),
|
||||
new Directive.import('package:file/file.dart'),
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
Expression createInstance(
|
||||
MethodBuilder methodBuilder, String name, String lower) {
|
||||
Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder,
|
||||
String name, String lower) {
|
||||
library.directives.addAll([
|
||||
new Directive.import('package:file/file.dart'),
|
||||
]);
|
||||
return refer('JsonFileService').newInstance([
|
||||
refer('dbDirectory')
|
||||
.property('childFile')
|
||||
|
|
|
@ -27,13 +27,18 @@ class ServiceGenerator {
|
|||
|
||||
void applyToLibrary(LibraryBuilder library, String name, String lower) {}
|
||||
|
||||
void beforeService(BlockBuilder builder, String name, String lower) {}
|
||||
void beforeService(LibraryBuilder library, BlockBuilder builder, String name,
|
||||
String lower) {}
|
||||
|
||||
void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block,
|
||||
String name, String lower) {}
|
||||
void applyToConfigureServer(
|
||||
LibraryBuilder library,
|
||||
MethodBuilder configureServer,
|
||||
BlockBuilder block,
|
||||
String name,
|
||||
String lower) {}
|
||||
|
||||
Expression createInstance(
|
||||
MethodBuilder methodBuilder, String name, String lower) =>
|
||||
Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder,
|
||||
String name, String lower) =>
|
||||
literal(null);
|
||||
|
||||
@override
|
||||
|
|
|
@ -8,8 +8,8 @@ class MapServiceGenerator extends ServiceGenerator {
|
|||
bool get createsModel => false;
|
||||
|
||||
@override
|
||||
Expression createInstance(
|
||||
MethodBuilder methodBuilder, String name, String lower) {
|
||||
Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder,
|
||||
String name, String lower) {
|
||||
return refer('MapService').newInstance([]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,12 @@ class MongoServiceGenerator extends ServiceGenerator {
|
|||
bool get createsModel => false;
|
||||
|
||||
@override
|
||||
void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block,
|
||||
String name, String lower) {
|
||||
void applyToConfigureServer(
|
||||
LibraryBuilder library,
|
||||
MethodBuilder configureServer,
|
||||
BlockBuilder block,
|
||||
String name,
|
||||
String lower) {
|
||||
configureServer.requiredParameters.add(new Parameter((b) => b
|
||||
..name = 'db'
|
||||
..type = refer('Db')));
|
||||
|
@ -30,8 +34,8 @@ class MongoServiceGenerator extends ServiceGenerator {
|
|||
}
|
||||
|
||||
@override
|
||||
Expression createInstance(
|
||||
MethodBuilder methodBuilder, String name, String lower) {
|
||||
Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder,
|
||||
String name, String lower) {
|
||||
return refer('MongoService').newInstance([
|
||||
refer('db').property('collection').call([literal(pluralize(lower))])
|
||||
]);
|
||||
|
|
|
@ -14,8 +14,12 @@ class RethinkServiceGenerator extends ServiceGenerator {
|
|||
bool get createsModel => false;
|
||||
|
||||
@override
|
||||
void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block,
|
||||
String name, String lower) {
|
||||
void applyToConfigureServer(
|
||||
LibraryBuilder library,
|
||||
MethodBuilder configureServer,
|
||||
BlockBuilder block,
|
||||
String name,
|
||||
String lower) {
|
||||
configureServer.requiredParameters.addAll([
|
||||
new Parameter((b) => b
|
||||
..name = 'connection'
|
||||
|
@ -35,8 +39,8 @@ class RethinkServiceGenerator extends ServiceGenerator {
|
|||
}
|
||||
|
||||
@override
|
||||
Expression createInstance(
|
||||
MethodBuilder methodBuilder, String name, String lower) {
|
||||
Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder,
|
||||
String name, String lower) {
|
||||
return refer('RethinkService').newInstance([
|
||||
refer('connection'),
|
||||
refer('r').property('table').call([literal(pluralize(lower))])
|
||||
|
|
Loading…
Reference in a new issue