Permalink
Browse files

Streamline generators initialization flow.

  • Loading branch information...
1 parent d1d34ce commit 594b749f3c81102a1f89480d0f8f10b464b895a7 @josevalim josevalim committed May 24, 2011
View
6 railties/lib/rails/application.rb
@@ -106,13 +106,13 @@ def load_tasks
def load_generators(app=self)
initialize_generators
railties.all { |r| r.load_generators(app) }
-
+ Rails::Generators.configure!(app.config.generators)
super
self
end
def load_console(sandbox=false)
- initialize_console(sandbox)
+ initialize_console
railties.all { |r| r.load_console(sandbox) }
super()
self
@@ -197,7 +197,7 @@ def initialize_generators
require "rails/generators"
end
- def initialize_console(sandbox=false)
+ def initialize_console
require "pp"
require "rails/console/app"
require "rails/console/helpers"
View
6 railties/lib/rails/commands.rb
@@ -15,14 +15,18 @@
case command
when 'generate', 'destroy', 'plugin'
+ require 'rails/generators'
+
if command == 'plugin' && ARGV.first == 'new'
require "rails/commands/plugin_new"
else
require APP_PATH
Rails.application.require_environment!
if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
- Rails.application = engine
+ Rails.application.load_generators(engine)
+ else
+ Rails.application.load_generators
end
require "rails/commands/#{command}"
View
2 railties/lib/rails/commands/destroy.rb
@@ -1,8 +1,6 @@
require 'rails/generators'
require 'active_support/core_ext/object/inclusion'
-Rails::Generators.configure!
-
if ARGV.first.in?([nil, "-h", "--help"])
Rails::Generators.help 'destroy'
exit
View
2 railties/lib/rails/commands/generate.rb
@@ -1,8 +1,6 @@
require 'rails/generators'
require 'active_support/core_ext/object/inclusion'
-Rails::Generators.configure!
-
if ARGV.first.in?([nil, "-h", "--help"])
Rails::Generators.help 'generate'
exit
View
4 railties/lib/rails/commands/plugin_new.rb
@@ -4,7 +4,5 @@
ARGV.shift
end
-require 'rails/generators'
require 'rails/generators/rails/plugin_new/plugin_new_generator'
-
-Rails::Generators::PluginNewGenerator.start
+Rails::Generators::PluginNewGenerator.start
View
12 railties/lib/rails/generators.rb
@@ -68,7 +68,7 @@ module Generators
}
}
- def self.configure!(config = Rails.application.config.generators) #:nodoc:
+ def self.configure!(config) #:nodoc:
no_color! unless config.colorize_logging
aliases.deep_merge! config.aliases
options.deep_merge! config.options
@@ -286,7 +286,6 @@ def self.invoke_fallbacks_for(name, base) #:nodoc:
# Receives namespaces in an array and tries to find matching generators
# in the load path.
def self.lookup(namespaces) #:nodoc:
- load_generators_from_railties!
paths = namespaces_to_paths(namespaces)
paths.each do |raw_path|
@@ -310,8 +309,6 @@ def self.lookup(namespaces) #:nodoc:
# This will try to load any generator in the load path to show in help.
def self.lookup! #:nodoc:
- load_generators_from_railties!
-
$LOAD_PATH.each do |base|
Dir[File.join(base, "{rails/generators,generators}", "**", "*_generator.rb")].each do |path|
begin
@@ -324,13 +321,6 @@ def self.lookup! #:nodoc:
end
end
- # Allow generators to be loaded from custom paths.
- def self.load_generators_from_railties! #:nodoc:
- return if defined?(@generators_from_railties) || Rails.application.nil?
- @generators_from_railties = true
- Rails.application.load_generators
- end
-
# Convert namespaces to paths by replacing ":" for "/" and adding
# an extra lookup. For example, "rails:model" should be searched
# in both: "rails/model/model_generator" and "rails/model_generator".
View
2 railties/test/generators/generators_test_helper.rb
@@ -12,7 +12,7 @@ def self.root
# Call configure to load the settings from
# Rails.application.config.generators to Rails::Generators
-Rails::Generators.configure!
+Rails::Generators.configure!(Rails.application.config.generators)
require 'active_record'
require 'action_dispatch'

0 comments on commit 594b749

Please sign in to comment.