Configure generator when needed rather than during initialization

This commit is contained in:
Jeremy Kemper 2009-11-03 18:58:40 -08:00
parent d627c932bd
commit a3d5274e67
5 changed files with 12 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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