diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:45:35 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:45:35 +0000 |
commit | b1999be5a7efd67e2602c37ed898aa8433661863 (patch) | |
tree | 03bc833276075d802d0ce0ad261baed3d7232533 /railties/lib/rails_generator/lookup.rb | |
parent | 88a3343ed57c01ca358da8473d15fc4d2b4a5bff (diff) | |
download | rails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.gz rails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.bz2 rails-b1999be5a7efd67e2602c37ed898aa8433661863.zip |
A hopefully more successful attempt at the Routing branch merge
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@617 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, 13 insertions, 17 deletions
diff --git a/railties/lib/rails_generator/lookup.rb b/railties/lib/rails_generator/lookup.rb index ba47fd79be..00b78ce645 100644 --- a/railties/lib/rails_generator/lookup.rb +++ b/railties/lib/rails_generator/lookup.rb @@ -4,24 +4,20 @@ 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 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 + # 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) 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 @@ -102,7 +98,7 @@ module Rails # 4. Builtins. Model, controller, mailer, scaffold. def use_component_sources! reset_sources - sources << PathSource.new(:app, "#{Object.const_get(:RAILS_ROOT)}/script/generators") if Object.const_defined?(:RAILS_ROOT) + sources << PathSource.new(:app, "#{::RAILS_ROOT}/script/generators") if 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") |