obsolete.ChilliProject/lib/generators/chiliproject_plugin_model/chiliproject_plugin_model_g...

60 lines
2.0 KiB
Ruby
Raw Normal View History

2011-10-29 16:19:11 +04:00
#-- encoding: UTF-8
#-- copyright
# ChiliProject is a project management system.
2011-05-30 22:52:25 +04:00
#
# Copyright (C) 2010-2012 the ChiliProject Team
2011-05-30 22:52:25 +04:00
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
2011-05-30 22:52:25 +04:00
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'rails_generator/base'
require 'rails_generator/generators/components/model/model_generator'
class ChiliprojectPluginModelGenerator < ModelGenerator
attr_accessor :plugin_path, :plugin_name, :plugin_pretty_name
2011-05-30 22:52:25 +04:00
def initialize(runtime_args, runtime_options = {})
runtime_args = runtime_args.dup
usage if runtime_args.empty?
@plugin_name = "chiliproject_" + runtime_args.shift.underscore
@plugin_pretty_name = plugin_name.titleize
@plugin_path = "vendor/plugins/#{plugin_name}"
super(runtime_args, runtime_options)
end
2011-05-30 22:52:25 +04:00
def destination_root
File.join(RAILS_ROOT, plugin_path)
end
2011-05-30 22:52:25 +04:00
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")
2011-05-30 22:52:25 +04:00
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
end
end