diff options
Diffstat (limited to 'railties/lib/rails/generators.rb')
-rw-r--r-- | railties/lib/rails/generators.rb | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 736c36c0dc..d3175e6a9d 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -168,7 +168,7 @@ module Rails # Show help message with available generators. def self.help - traverse_load_paths! + lookup! namespaces = subclasses.map{ |k| k.namespace } namespaces.sort! @@ -226,22 +226,10 @@ module Rails nil end - # This will try to load any generator in the load path to show in help. - def self.traverse_load_paths! #:nodoc: - $LOAD_PATH.each do |base| - Dir[File.join(base, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path| - begin - require path - rescue Exception => e - # No problem - end - end - end - end - # 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 |path| @@ -261,6 +249,28 @@ module Rails end end + # 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, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path| + begin + require path + rescue Exception => e + # No problem + end + end + 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". |