I have ported a few Rails 2 generators in the past week and have
learned a lot doing it, but I still don’t understand how to take
advantage of the new ‘hook’ functionality, which should make it easy
to hook up multiple generators and have one generator calling multiple
other generators.
Anyone has any idea how this works from a generator perspective and
how to extend and customize it.
I know there are some trivial examples in the official Rails guide.
Do you simply have to specify the hooks in the application.rb in the
config section and then add hooks in the
generators matching these names?
application.rb
Config… do |config|
config.orm :mongo_db
config.form :formtastic
end
class MyGenerator < Rails::Generators::Base
…
hook_for :formtastic
hook_for :model
end
This all seems very magical and too transparent to work with without
some more understanding of what goes on underneath and how it all
connects. There are also the :in and :as options for hook_for. How are
they used?
There is also rules for how the hooks are resolved…
Thanks for any info
Kristian