diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-26 19:30:18 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-26 19:30:18 +0200 |
commit | e981aeb57633148b02a96db13d2c63bc84c4555f (patch) | |
tree | 7c9ae5527685dc73e3b34bbdd8499a15d2a02070 /railties | |
parent | 5ef1d9706bfca6362a6eb29820affb98af17e400 (diff) | |
download | rails-e981aeb57633148b02a96db13d2c63bc84c4555f.tar.gz rails-e981aeb57633148b02a96db13d2c63bc84c4555f.tar.bz2 rails-e981aeb57633148b02a96db13d2c63bc84c4555f.zip |
invoke_for now uses Rails built-in lookup.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/generators/base.rb | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index 564496ad52..0eca5ec008 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -118,7 +118,26 @@ module Rails end # Invoke a generator based on the given name. If a class option does not - # exist for the current name, it's created. + # exist for the current name, one created. + # + # ==== Examples + # + # class ControllerGenerator < Rails::Generators::Base + # invoke_for :test_framework + # end + # + # The example above will create a test framework option and will invoke + # a generator based on the user supplied value. + # + # For example, if the user invoke the controller generator as: + # + # ruby script/generate controller Account --test-framework=test_unit + # + # The controller generator will then invoke "test_unit:generators:controller". + # If it can't be found it then tries to invoke only "test_unit". + # + # This allows any test framework to hook into Rails as long as it + # provides a "test_framework:generators:controller" generator. # def self.invoke_for(*names) names.each do |name| @@ -131,11 +150,14 @@ module Rails class_eval <<-METHOD, __FILE__, __LINE__ def invoke_#{name} return unless options[#{name.inspect}] - task = "\#{options[#{name.inspect}]}:generators:\#{self.class.generator_name}" - begin - invoke task - rescue Thor::UndefinedTaskError + klass = Rails::Generators.find_by_namespace(options[#{name.inspect}], + nil, self.class.generator_name) + + if klass + invoke klass + else + task = "\#{options[#{name.inspect}]}:generators:\#{self.class.generator_name}" say "Could not find and invoke '\#{task}'." end end |