Froze rails gems
[depot.git] / vendor / rails / railties / lib / rails_generator / generators / components / model / model_generator.rb
1 class ModelGenerator < Rails::Generator::NamedBase
2 default_options :skip_timestamps => false, :skip_migration => false, :skip_fixture => false
3
4 def manifest
5 record do |m|
6 # Check for class naming collisions.
7 m.class_collisions class_name, "#{class_name}Test"
8
9 # Model, test, and fixture directories.
10 m.directory File.join('app/models', class_path)
11 m.directory File.join('test/unit', class_path)
12 m.directory File.join('test/fixtures', class_path)
13
14 # Model class, unit test, and fixtures.
15 m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
16 m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
17
18 unless options[:skip_fixture]
19 m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
20 end
21
22 unless options[:skip_migration]
23 m.migration_template 'migration.rb', 'db/migrate', :assigns => {
24 :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
25 }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
26 end
27 end
28 end
29
30 protected
31 def banner
32 "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
33 end
34
35 def add_options!(opt)
36 opt.separator ''
37 opt.separator 'Options:'
38 opt.on("--skip-timestamps",
39 "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
40 opt.on("--skip-migration",
41 "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
42 opt.on("--skip-fixture",
43 "Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v}
44 end
45 end