DRY up app generator and plugin new generator. Moved shared options to AppBase generator

This commit is contained in:
Piotr Sarnacki 2010-10-23 20:42:01 +02:00
parent 68295bc693
commit d995953869
3 changed files with 31 additions and 52 deletions

@ -8,6 +8,34 @@
module Rails
module Generators
class AppBase < Base
attr_accessor :rails_template
add_shebang_option!
argument :app_path, :type => :string
def self.add_shared_options_for(name)
class_option :builder, :type => :string, :aliases => "-b",
:desc => "Path to a #{name} builder (can be a filesystem path or URL)"
class_option :template, :type => :string, :aliases => "-m",
:desc => "Path to an #{name} template (can be a filesystem path or URL)"
class_option :skip_gemfile, :type => :boolean, :default => false,
:desc => "Don't create a Gemfile"
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
:desc => "Skip Git ignores and keeps"
class_option :dev, :type => :boolean, :default => false,
:desc => "Setup the #{name} with Gemfile pointing to your Rails checkout"
class_option :edge, :type => :boolean, :default => false,
:desc => "Setup the #{name} with Gemfile pointing to Rails repository"
class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
:desc => "Show this help message and quit"
end
def self.say_step(message)
@step = (@step || 0) + 1
class_eval <<-METHOD, __FILE__, __LINE__ + 1

@ -157,10 +157,7 @@ class AppGenerator < AppBase
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
JAVASCRIPTS = %w( prototype jquery )
attr_accessor :rails_template
add_shebang_option!
argument :app_path, :type => :string
add_shared_options_for "application"
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
@ -168,21 +165,6 @@ class AppGenerator < AppBase
class_option :javascript, :type => :string, :aliases => "-j", :default => "prototype",
:desc => "Preconfigure for selected javascript library (options: #{JAVASCRIPTS.join('/')})"
class_option :builder, :type => :string, :aliases => "-b",
:desc => "Path to an application builder (can be a filesystem path or URL)"
class_option :template, :type => :string, :aliases => "-m",
:desc => "Path to an application template (can be a filesystem path or URL)"
class_option :dev, :type => :boolean, :default => false,
:desc => "Setup the application with Gemfile pointing to your Rails checkout"
class_option :edge, :type => :boolean, :default => false,
:desc => "Setup the application with Gemfile pointing to Rails repository"
class_option :skip_gemfile, :type => :boolean, :default => false,
:desc => "Don't create a Gemfile"
class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false,
:desc => "Skip Active Record files"
@ -192,16 +174,10 @@ class AppGenerator < AppBase
class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false,
:desc => "Skip javascript files"
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
:desc => "Skip Git ignores and keeps"
# Add bin/rails options
class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
:desc => "Show Rails version number and quit"
class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
:desc => "Show this help message and quit"
def initialize(*args)
raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank?

@ -92,34 +92,9 @@ def test_path
module Generators
class PluginNewGenerator < AppBase
attr_accessor :rails_template
add_shebang_option!
argument :plugin_path, :type => :string
alias_method :app_path, :plugin_path
class_option :builder, :type => :string, :aliases => "-b",
:desc => "Path to a plugin builder (can be a filesystem path or URL)"
class_option :template, :type => :string, :aliases => "-m",
:desc => "Path to an application template (can be a filesystem path or URL)"
class_option :skip_gemfile, :type => :boolean, :default => false,
:desc => "Don't create a Gemfile"
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
:desc => "Skip Git ignores and keeps"
class_option :dev, :type => :boolean, :default => false,
:desc => "Setup the plugin with Gemfile pointing to your Rails checkout"
class_option :edge, :type => :boolean, :default => false,
:desc => "Setup the plugin with Gemfile pointing to Rails repository"
class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
:desc => "Show this help message and quit"
add_shared_options_for "plugin"
alias_method :plugin_path, :app_path
def initialize(*args)
raise Error, "Options should be given after the plugin name. For details run: rails plugin --help" if args[0].blank?