lib/bivouac/commands/generate.rb in bivouac-0.2.2 vs lib/bivouac/commands/generate.rb in bivouac-0.2.3
- old
+ new
@@ -243,22 +243,23 @@
end
model_list = @script_arguments
else
model_list = [ model ]
end
-
- model_list.each do |model_name|
+
+ model_name = model_list.shift
+ #model_list.each do |model_name|
# Model class name, passed to the template
@model_class_name = model_name.classify
destination_file = File.dirname( $0 ) + "/../app/models/" + @model_class_name.underscore + ".rb"
createFile( destination_file ) do |io|
io.puts template( "generate/model", binding )
end
- migration( model_name )
- end
+ migration( [model_name] + model_list )
+ #end
end
def migration( model = nil )
# Test options
argument_options = OptionParser.new do |opts|
@@ -281,11 +282,11 @@
end
model = @script_arguments
from_model = false
else
- model = [ model ]
+ # model = [ model ]
from_model = true
end
# Get old and new version
old_version = 0.0
@@ -311,26 +312,46 @@
files = files.sort {|x,y| y[0,3] <=> x[0,3]}
file_prefix = sprintf( "%03d", (files[0][0,3].to_i + 1) )
end
puts "\t* Migration from version #{old_version} to version #{@new_version}" if old_version > 0.0
-
- model.each do |model_name|
+
+ model_name = model.shift
+ # model.each do |model_name|
# Model class name
@model_class_name = model_name.classify
- # Model class name
- @model_table_name = (@app.environment.appname.downcase + "_" + model_name).tableize
-
destination_file = File.dirname( $0 ) + "/../db/migrate/" + file_prefix + "_" + model_name.underscore + ".rb"
createFile( destination_file ) do |io|
if from_model
- io.puts template( "generate/migrate", binding )
+ # Model table name
+ @model_table_name = (@app.environment.appname.downcase + "_" + model_name).tableize
+
+ io.puts template( "generate/migrate_begin", binding )
+
+ model.each do |column|
+ @model_data_name, @model_data_type = column.split( /:/ )
+ io.puts template( "generate/migrate_column", binding )
+ end
+
+ io.puts template( "generate/migrate_end", binding )
else
- io.puts template( "generate/migration", binding )
+ # Model table name
+ @model_table_name = (@app.environment.appname.downcase + "_" + (model_name.underscore.split( /_/ ))[-1]).tableize
+ io.puts template( "generate/migration_begin", binding )
+ model.each do |column|
+ @model_data_name, @model_data_type = column.split( /:/ )
+ io.puts template( "generate/migration_add", binding )
+ end
+ io.puts template( "generate/migration_middle", binding )
+ model.each do |column|
+ @model_data_name, @model_data_type = column.split( /:/ )
+ io.puts template( "generate/migration_remove", binding )
+ end
+ io.puts template( "generate/migration_end", binding )
end
end
- end
+ # end
destination_file = File.dirname( $0 ) + "/../db/create.rb"
createFile( destination_file, false, false ) do |io|
io.puts template( "generate/create", binding )
end