Where is the code that lets you override the templates that the generators use?

In the rails documentation, it states that:

In Rails 3.0 and above, generators don’t just look in the source root for templates, they also search for templates in other paths. And one of them is lib/templates. Since we want to customize Rails::Generators::HelperGenerator, we can do that by simply making a template copy inside lib/templates/rails/helper with the name helper.rb.

I’m trying to dig through the rails source code to see where this lookup occurs. I’ve gotten this far.

In railties/lib/rails/generators/rails/helper/helper_generator.rb, the code

template 'helper.rb', File.join('app/helpers', class_path, "#{file_name}_helper.rb")

seems to be calling the super class’ method (railties/lib/rails/generators/named_base.rb): # Defines the template that would be used for the migration file.

The arguments include the source template file, the migration filename etc.

no_tasks do

def template(source, *args, &block)

inside_template do

super

end

end

end

This in turn inherits from name_base inherits from base, but the method “template” doesnt seem to appear in that class.

Where can I find the code that does this lookup?