Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DRY up app generator and plugin new generator. Moved shared options t…

…o AppBase generator
  • Loading branch information...
commit d995953869ca09906af8f5c5058d47cb66bc2467 1 parent 68295bc
@drogus drogus authored
View
28 railties/lib/rails/generators/app_base.rb
@@ -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
View
26 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -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?
View
29 railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -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?
Please sign in to comment.
Something went wrong with that request. Please try again.