lib/generators/model_generator/model_generator.rb in mack-0.4.6 vs lib/generators/model_generator/model_generator.rb in mack-0.4.7
- old
+ new
@@ -15,11 +15,13 @@
# end
# end
#
# If using DataMapper generates:
# app/models/user.rb:
-# class User < DataMapper::Base
+# class User
+# include DataMapper::Persistence
+#
# end
# db/migrations/<number>_create_users.rb:
# class CreateUsers < DataMapper::Migration
# self.up
# end
@@ -49,11 +51,13 @@
# end
# end
#
# If using DataMapper generates:
# app/models/user.rb:
-# class User < DataMapper::Base
+# class User
+# include DataMapper::Persistence
+#
# property :username, :string
# property :email_address, :string
# property :created_at, :datetime
# property :updated_at, :datetime
# end
@@ -69,28 +73,21 @@
#
# self.down
# drop_table :users
# end
# end
-class ModelGenerator < Mack::Generator::Base
+class ModelGenerator < Genosaurus
require_param :name
- def generate
- directory(File.join(MACK_APP, "models"))
-
- @columns = ""
- cols = (param(:cols) || param(:columns))
- if cols
- cols = cols.split("|")
- cols.each_with_index do |v, i|
- x = v.split(":")
- @columns << "property :#{x.first}, :#{x.last}\n "
- end
- @columns.strip!
- end
-
- template(File.join(File.dirname(__FILE__), "templates", "app", "models", "#{app_config.orm}.rb.template"), File.join(MACK_APP, "models", "#{param(:name).singular.underscore}.rb"), :force => param(:force))
- MigrationGenerator.new(@env.merge({"name" => "create_#{param(:name).plural}"})).generate
+ # def generate
+ # directory(File.join(MACK_APP, "models"))
+ #
+ # template(File.join(File.dirname(__FILE__), "templates", "app", "models", "#{app_config.orm}.rb.template"), File.join(MACK_APP, "models", "#{param(:name).singular.underscore}.rb"), :force => param(:force))
+ # MigrationGenerator.new(@env.merge({"name" => "create_#{param(:name).plural}"})).generate
+ # end
+
+ def after_generate
+ MigrationGenerator.run(@options.merge({"name" => "create_#{param(:name).plural}"}))
end
end
\ No newline at end of file