@@ -1,45 +1,45 | |||||
1 | require 'rails_generator/base' |
|
1 | require 'rails_generator/base' | |
2 | require 'rails_generator/generators/components/model/model_generator' |
|
2 | require 'rails_generator/generators/components/model/model_generator' | |
3 |
|
3 | |||
4 | class RedminePluginModelGenerator < ModelGenerator |
|
4 | class RedminePluginModelGenerator < ModelGenerator | |
5 | attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name |
|
5 | attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name | |
6 |
|
6 | |||
7 | def initialize(runtime_args, runtime_options = {}) |
|
7 | def initialize(runtime_args, runtime_options = {}) | |
8 | runtime_args = runtime_args.dup |
|
8 | runtime_args = runtime_args.dup | |
9 | usage if runtime_args.empty? |
|
9 | usage if runtime_args.empty? | |
10 | @plugin_name = "redmine_" + runtime_args.shift.underscore |
|
10 | @plugin_name = "redmine_" + runtime_args.shift.underscore | |
11 | @plugin_pretty_name = plugin_name.titleize |
|
11 | @plugin_pretty_name = plugin_name.titleize | |
12 | @plugin_path = "vendor/plugins/#{plugin_name}" |
|
12 | @plugin_path = "vendor/plugins/#{plugin_name}" | |
13 | super(runtime_args, runtime_options) |
|
13 | super(runtime_args, runtime_options) | |
14 | end |
|
14 | end | |
15 |
|
15 | |||
16 | def destination_root |
|
16 | def destination_root | |
17 | File.join(Rails.root, plugin_path) |
|
17 | File.join(Rails.root, plugin_path) | |
18 | end |
|
18 | end | |
19 |
|
19 | |||
20 | def manifest |
|
20 | def manifest | |
21 | record do |m| |
|
21 | record do |m| | |
22 | # Check for class naming collisions. |
|
22 | # Check for class naming collisions. | |
23 | m.class_collisions class_path, class_name, "#{class_name}Test" |
|
23 | m.class_collisions class_path, class_name, "#{class_name}Test" | |
24 |
|
24 | |||
25 | # Model, test, and fixture directories. |
|
25 | # Model, test, and fixture directories. | |
26 | m.directory File.join('app/models', class_path) |
|
26 | m.directory File.join('app/models', class_path) | |
27 | m.directory File.join('test/unit', class_path) |
|
27 | m.directory File.join('test/unit', class_path) | |
28 | m.directory File.join('test/fixtures', class_path) |
|
28 | m.directory File.join('test/fixtures', class_path) | |
29 |
|
29 | |||
30 | # Model class, unit test, and fixtures. |
|
30 | # Model class, unit test, and fixtures. | |
31 | m.template 'model.rb.erb', File.join('app/models', class_path, "#{file_name}.rb") |
|
31 | m.template 'model.rb.erb', File.join('app/models', class_path, "#{file_name}.rb") | |
32 | m.template 'unit_test.rb.erb', File.join('test/unit', class_path, "#{file_name}_test.rb") |
|
32 | m.template 'unit_test.rb.erb', File.join('test/unit', class_path, "#{file_name}_test.rb") | |
33 |
|
33 | |||
34 |
unless options[:skip_fixture] |
|
34 | unless options[:skip_fixture] | |
35 | m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml") |
|
35 | m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml") | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | unless options[:skip_migration] |
|
38 | unless options[:skip_migration] | |
39 | m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => { |
|
39 | m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => { | |
40 | :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" |
|
40 | :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" | |
41 | }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" |
|
41 | }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 | end |
|
45 | end |
General Comments 0
You need to be logged in to leave comments.
Login now