diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:24:55 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:24:55 +0000 |
commit | 88a3343ed57c01ca358da8473d15fc4d2b4a5bff (patch) | |
tree | 3fe773bb113480f68eaea508d241cbaf90eebfde /railties/lib/rails_generator/lookup.rb | |
parent | 60f7a5cab73fab032fdb73d1a9a8061cf20031d2 (diff) | |
download | rails-88a3343ed57c01ca358da8473d15fc4d2b4a5bff.tar.gz rails-88a3343ed57c01ca358da8473d15fc4d2b4a5bff.tar.bz2 rails-88a3343ed57c01ca358da8473d15fc4d2b4a5bff.zip |
Backed out of routing merge.. investigating missing patches
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@616 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails_generator/lookup.rb')
-rw-r--r-- | railties/lib/rails_generator/lookup.rb | 30 |
1 files changed, 17 insertions, 13 deletions
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") |