From a3d5274e67c841a6fdc9f9acb9e1b6bbc351dd28 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 3 Nov 2009 18:58:40 -0800 Subject: Configure generator when needed rather than during initialization --- railties/lib/rails/application.rb | 12 ------------ railties/lib/rails/generators.rb | 6 ++++++ .../rails/generators/rails/app/templates/script/destroy.tt | 3 ++- .../rails/generators/rails/app/templates/script/generate.tt | 3 ++- railties/test/application/generators_test.rb | 3 ++- 5 files changed, 12 insertions(+), 15 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index ce3ab9147c..242aea1842 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -412,18 +412,6 @@ module Rails end end - # Configure generators if they were already loaded - # === - # TODO: Does this need to be an initializer here? - initializer :initialize_generators do - if defined?(RAILS_GENERATORS) && RAILS_GENERATORS - require 'rails/generators' - Rails::Generators.no_color! unless config.generators.colorize_logging - Rails::Generators.aliases.deep_merge! config.generators.aliases - Rails::Generators.options.deep_merge! config.generators.options - end - end - # For each framework, search for instrument file with Notifications hooks. # initializer :load_notifications_hooks do diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index a6a59f039f..fa2c11795b 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -72,6 +72,12 @@ module Rails } } + def self.configure!(config = Rails.application.config.generators) #:nodoc: + no_color! unless config.colorize_logging + aliases.deep_merge! config.aliases + options.deep_merge! config.options + end + def self.aliases #:nodoc: @aliases ||= DEFAULT_ALIASES.dup end diff --git a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt b/railties/lib/rails/generators/rails/app/templates/script/destroy.tt index 62a856d338..6adc90b2c3 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/destroy.tt @@ -1,4 +1,5 @@ <%= shebang %> -RAILS_GENERATORS = true require File.expand_path('../../config/environment', __FILE__) +require 'rails/generators' +Rails::Generators.configure! require 'rails/commands/destroy' diff --git a/railties/lib/rails/generators/rails/app/templates/script/generate.tt b/railties/lib/rails/generators/rails/app/templates/script/generate.tt index a005e77104..71d47dec92 100755 --- a/railties/lib/rails/generators/rails/app/templates/script/generate.tt +++ b/railties/lib/rails/generators/rails/app/templates/script/generate.tt @@ -1,4 +1,5 @@ <%= shebang %> -RAILS_GENERATORS = true require File.expand_path('../../config/environment', __FILE__) +require 'rails/generators' +Rails::Generators.configure! require 'rails/commands/generate' diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index bfbf1ffd16..ccbcd84176 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -1,5 +1,4 @@ require "isolation/abstract_unit" -RAILS_GENERATORS = true module ApplicationTests class GeneratorsTest < Test::Unit::TestCase @@ -47,6 +46,7 @@ module ApplicationTests end # Initialize the application Rails.initialize! + Rails::Generators.configure! assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] @@ -59,6 +59,7 @@ module ApplicationTests end # Initialize the application Rails.initialize! + Rails::Generators.configure! assert_equal Thor::Base.shell, Thor::Shell::Basic end -- cgit v1.2.3