To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 18 / 18d3632a00930fda235a1df851a99c522ae0e846.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (1.61 KB)
| 1 |
require 'rails_generator/base' |
|---|---|
| 2 |
require 'rails_generator/generators/components/model/model_generator' |
| 3 |
|
| 4 |
class RedminePluginModelGenerator < ModelGenerator |
| 5 |
attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name |
| 6 |
|
| 7 |
def initialize(runtime_args, runtime_options = {})
|
| 8 |
runtime_args = runtime_args.dup |
| 9 |
usage if runtime_args.empty? |
| 10 |
@plugin_name = "redmine_" + runtime_args.shift.underscore |
| 11 |
@plugin_pretty_name = plugin_name.titleize |
| 12 |
@plugin_path = "vendor/plugins/#{plugin_name}"
|
| 13 |
super(runtime_args, runtime_options) |
| 14 |
end |
| 15 |
|
| 16 |
def destination_root |
| 17 |
File.join(Rails.root, plugin_path) |
| 18 |
end |
| 19 |
|
| 20 |
def manifest |
| 21 |
record do |m| |
| 22 |
# Check for class naming collisions. |
| 23 |
m.class_collisions class_path, class_name, "#{class_name}Test"
|
| 24 |
|
| 25 |
# Model, test, and fixture directories. |
| 26 |
m.directory File.join('app/models', class_path)
|
| 27 |
m.directory File.join('test/unit', class_path)
|
| 28 |
m.directory File.join('test/fixtures', class_path)
|
| 29 |
|
| 30 |
# Model class, unit test, and fixtures. |
| 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")
|
| 33 |
|
| 34 |
unless options[:skip_fixture] |
| 35 |
m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
|
| 36 |
end |
| 37 |
|
| 38 |
unless options[:skip_migration] |
| 39 |
m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
|
| 40 |
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
| 41 |
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
| 42 |
end |
| 43 |
end |
| 44 |
end |
| 45 |
end |