From 88a3343ed57c01ca358da8473d15fc4d2b4a5bff Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 15 Feb 2005 01:24:55 +0000 Subject: Backed out of routing merge.. investigating missing patches git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@616 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/rails_generator/lookup.rb | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'railties/lib/rails_generator/lookup.rb') diff --git a/railties/lib/rails_generator/lookup.rb b/railties/lib/rails_generator/lookup.rb index 00b78ce645..ba47fd79be 100644 --- a/railties/lib/rails_generator/lookup.rb +++ b/railties/lib/rails_generator/lookup.rb @@ -4,20 +4,24 @@ class Object class << self # Lookup missing generators using const_missing. This allows any # generator to reference another without having to know its location: - # RubyGems, ~/.rails/generators, and RAILS_ROOT/script/generators. - def lookup_missing_generator(class_id) - if md = /(.+)Generator$/.match(class_id.to_s) - name = md.captures.first.demodulize.underscore - Rails::Generator::Base.lookup(name).klass - else - const_missing_before_generators(class_id) + # RubyGems, ~/.rails/generators, and RAILS_ROOT/script/generators all + # cooperate to get the job done. The greatest use of const_missing + # autoloading is to easily subclass existing generators. Example: + # class HorsebackGenerator < PostbackGenerator + # We don't know whether the postback generator is built in, installed + # as a gem, or in the user's home directory, and we shouldn't have to. + unless respond_to?(:pre_generator_const_missing) + alias_method :pre_generator_const_missing, :const_missing + + def const_missing(class_id) + if md = /(.+)Generator$/.match(class_id.to_s) + name = md.captures.first.demodulize.underscore + Rails::Generator::Base.lookup(name).klass + else + pre_generator_const_missing(class_id) + end end end - - unless respond_to?(:const_missing_before_generators) - alias_method :const_missing_before_generators, :const_missing - alias_method :const_missing, :lookup_missing_generator - end end end @@ -98,7 +102,7 @@ module Rails # 4. Builtins. Model, controller, mailer, scaffold. def use_component_sources! reset_sources - sources << PathSource.new(:app, "#{::RAILS_ROOT}/script/generators") if defined? ::RAILS_ROOT + sources << PathSource.new(:app, "#{Object.const_get(:RAILS_ROOT)}/script/generators") if Object.const_defined?(:RAILS_ROOT) sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators") sources << GemSource.new if Object.const_defined?(:Gem) sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components") -- cgit v1.2.3