summaryrefslogtreecommitdiffstats
path: root/lib/generators/redmine_plugin_model
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generators/redmine_plugin_model')
-rw-r--r--lib/generators/redmine_plugin_model/USAGE2
-rw-r--r--lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb50
-rw-r--r--lib/generators/redmine_plugin_model/templates/fixtures.yml11
-rw-r--r--lib/generators/redmine_plugin_model/templates/migration.rb.erb13
-rw-r--r--lib/generators/redmine_plugin_model/templates/model.rb.erb2
-rw-r--r--lib/generators/redmine_plugin_model/templates/unit_test.rb.erb3
6 files changed, 15 insertions, 66 deletions
diff --git a/lib/generators/redmine_plugin_model/USAGE b/lib/generators/redmine_plugin_model/USAGE
index 0cb55a186..f070d5493 100644
--- a/lib/generators/redmine_plugin_model/USAGE
+++ b/lib/generators/redmine_plugin_model/USAGE
@@ -2,4 +2,4 @@ Description:
Generates a plugin model.
Examples:
- ./script/generate redmine_plugin_model MyPlugin pool title:string question:text
+ ./script/generate redmine_plugin_model meetings pool
diff --git a/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb b/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
index 07aff1fb7..01ce31b1d 100644
--- a/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
+++ b/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
@@ -1,45 +1,19 @@
-require 'rails_generator/base'
-require 'rails_generator/generators/components/model/model_generator'
+class RedminePluginModelGenerator < Rails::Generators::NamedBase
+ source_root File.expand_path("../templates", __FILE__)
+ argument :model, :type => :string
-class RedminePluginModelGenerator < ModelGenerator
- attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name
+ attr_reader :plugin_path, :plugin_name, :plugin_pretty_name
- def initialize(runtime_args, runtime_options = {})
- runtime_args = runtime_args.dup
- usage if runtime_args.empty?
- @plugin_name = "redmine_" + runtime_args.shift.underscore
+ def initialize(*args)
+ super
+ @plugin_name = file_name.underscore
@plugin_pretty_name = plugin_name.titleize
- @plugin_path = "vendor/plugins/#{plugin_name}"
- super(runtime_args, runtime_options)
+ @plugin_path = "plugins/#{plugin_name}"
+ @model_class = model.camelize
end
- def destination_root
- File.join(Rails.root, plugin_path)
- end
-
- def manifest
- record do |m|
- # Check for class naming collisions.
- m.class_collisions class_path, class_name, "#{class_name}Test"
-
- # Model, test, and fixture directories.
- m.directory File.join('app/models', class_path)
- m.directory File.join('test/unit', class_path)
- m.directory File.join('test/fixtures', class_path)
-
- # Model class, unit test, and fixtures.
- m.template 'model.rb.erb', File.join('app/models', class_path, "#{file_name}.rb")
- m.template 'unit_test.rb.erb', File.join('test/unit', class_path, "#{file_name}_test.rb")
-
- unless options[:skip_fixture]
- m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
- end
-
- unless options[:skip_migration]
- m.migration_template 'migration.rb.erb', 'db/migrate', :assigns => {
- :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
- }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
- end
- end
+ def copy_templates
+ template 'model.rb.erb', "#{plugin_path}/app/models/#{model}.rb"
+ template 'unit_test.rb.erb', "#{plugin_path}/test/unit/#{model}_test.rb"
end
end
diff --git a/lib/generators/redmine_plugin_model/templates/fixtures.yml b/lib/generators/redmine_plugin_model/templates/fixtures.yml
deleted file mode 100644
index 6be3c81be..000000000
--- a/lib/generators/redmine_plugin_model/templates/fixtures.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-one:
- id: 1
-<% for attribute in attributes -%>
- <%= attribute.name %>: <%= attribute.default %>
-<% end -%>
-two:
- id: 2
-<% for attribute in attributes -%>
- <%= attribute.name %>: <%= attribute.default %>
-<% end -%>
diff --git a/lib/generators/redmine_plugin_model/templates/migration.rb.erb b/lib/generators/redmine_plugin_model/templates/migration.rb.erb
deleted file mode 100644
index 2a305a6a9..000000000
--- a/lib/generators/redmine_plugin_model/templates/migration.rb.erb
+++ /dev/null
@@ -1,13 +0,0 @@
-class <%= migration_name %> < ActiveRecord::Migration
- def self.up
- create_table :<%= table_name %> do |t|
-<% for attribute in attributes -%>
- t.column :<%= attribute.name %>, :<%= attribute.type %>
-<% end -%>
- end
- end
-
- def self.down
- drop_table :<%= table_name %>
- end
-end
diff --git a/lib/generators/redmine_plugin_model/templates/model.rb.erb b/lib/generators/redmine_plugin_model/templates/model.rb.erb
index e730492b0..71284e96d 100644
--- a/lib/generators/redmine_plugin_model/templates/model.rb.erb
+++ b/lib/generators/redmine_plugin_model/templates/model.rb.erb
@@ -1,3 +1,3 @@
-class <%= class_name %> < ActiveRecord::Base
+class <%= @model_class %> < ActiveRecord::Base
unloadable
end
diff --git a/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb b/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb
index bc6ae913b..531510470 100644
--- a/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb
+++ b/lib/generators/redmine_plugin_model/templates/unit_test.rb.erb
@@ -1,7 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class <%= class_name %>Test < ActiveSupport::TestCase
- fixtures :<%= table_name %>
+class <%= @model_class %>Test < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth