Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / Experiments / Generator / Generators / Model / ModelGenerator.boo
blob519fb08deeb7d8ce0bd8c65fbd4134be4936f3f1
1 import System.IO
3 class ModelGenerator(NamedGeneratorBase):
4 [Property(Fields)] _fields as (string)
5 [Property(Properties)] _properties as (string)
6 [Option('no-migration', 'm', "Don't generate migration")]
7 _noMigration as bool
9 def Run():
10 _fields = [arg.ToVarName() for arg in Argv].ToArray(string)
11 _properties = [arg.ToClassName() for arg in Argv].ToArray(string)
13 MkDir(ModelsBasePath)
14 Process('Model.cs', "${ModelsBasePath}/${ClassName}.cs")
15 MkDir(ModelsTestsBasePath)
16 Process('Test.cs', "${ModelsTestsBasePath}/${ClassName}Test.cs")
18 if not _noMigration:
19 MkDir(MigrationsBasePath)
20 migrationVersion = string.Format("{0:000}", Version)
22 Process('Migration.cs', "${MigrationsBasePath}/${migrationVersion}_Add${ClassName}Table.cs")
24 def Usage():
25 return 'ModelName [Property1, Property2, ...]'
27 def Help():
28 return 'Generates an ActiveRecord model class'
30 Namespace:
31 get:
32 return ModelsNamespace
34 TestsNamespace:
35 get:
36 return ModelsTestsNamespace
38 UseGeneric as bool:
39 get:
40 return Framework == "net-2.0"
42 Version as int:
43 get:
44 return LastVersion+1
46 LastVersion as int:
47 get:
48 return 1 unless Directory.Exists("${MigrationsBasePath}")
49 max = 0
50 for file in Directory.GetFiles("${MigrationsBasePath}"):
51 info = FileInfo(file)
52 if info.Name.Substring(3, 1) == '_':
53 v = int.Parse(info.Name.Substring(0, 3))
54 max = v if v > max
55 return max
57 MigrationNamespace:
58 get:
59 return MigrationsNamespace