1 class ModelGenerator
< Rails
::Generator::NamedBase
2 default_options
:skip_timestamps => false, :skip_migration => false, :skip_fixture => false
6 # Check for class naming collisions.
7 m
.class_collisions class_name
, "#{class_name}Test"
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
)
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")
18 unless options
[:skip_fixture]
19 m
.template
'fixtures.yml', File
.join('test/fixtures', "#{table_name}.yml")
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}"
32 "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
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
}