I have two generators, one of which depends upon the other. I''d like to have the second one invoke the first. Instead of doing it via inserting a Rails::Generate::Scripts::Generate.new.run command in the second''s manifest, is there a way to essentially concat two manifests so that if I want to rewind the dependent generator''s manifest, it will also rewind the base generator''s manifest? I know this is a little vague - I guess I''d like something like (which obviously doesn''t work, just trying to give an idea): class DerivedGenerator < BaseGenerator def manifest record |m| super.replay(m) end end end
Joseph Hosteny wrote:> I have two generators, one of which depends upon the other. I''d like to > have the second one invoke the first. Instead of doing it via inserting > a Rails::Generate::Scripts::Generate.new.run > command in the second''s manifest, is there a way to essentially concat > two manifests so that if I want to rewind the dependent generator''s > manifest, it will also rewind the base generator''s manifest? > > I know this is a little vague - I guess I''d like something like (which > obviously doesn''t work, just trying to give an idea): > > class DerivedGenerator < BaseGenerator > def manifest > record |m| > super.replay(m) > end > end > endUse a dependency: class SomeGenerator < Rails::Generator::NamedBase def manifest record do |m| # Include some other generator. m.dependency ''another_generator_name'', [arg1, arg2], { options } # Include a model. m.dependency ''model'', [singular_name], :collision => :skip # Continue with your own manifest. # ... end end end I''m interested that you picked up on creating new generators; the framework is rather well-hidden within Rails and lacks a good HOWTO. Do you find yourself systematically editing the code from script/generate? Then write a generator to produce code in your own style. jeremy
Jeremy, Mainly, I just dug through the generators for controllers and models, as well as some generators available on the rails homepage. I also spent some time reading the code in rails_generator. Thanks for the quick answer. Joe On Apr 21, 2005, at 12:54 PM, Jeremy Kemper wrote:> Joseph Hosteny wrote: >> I have two generators, one of which depends upon the other. I''d like >> to >> have the second one invoke the first. Instead of doing it via >> inserting >> a Rails::Generate::Scripts::Generate.new.run >> command in the second''s manifest, is there a way to essentially concat >> two manifests so that if I want to rewind the dependent generator''s >> manifest, it will also rewind the base generator''s manifest? >> >> I know this is a little vague - I guess I''d like something like (which >> obviously doesn''t work, just trying to give an idea): >> >> class DerivedGenerator < BaseGenerator >> def manifest >> record |m| >> super.replay(m) >> end >> end >> end > > Use a dependency: > > class SomeGenerator < Rails::Generator::NamedBase > def manifest > record do |m| > # Include some other generator. > m.dependency ''another_generator_name'', [arg1, arg2], { options > } > > # Include a model. > m.dependency ''model'', [singular_name], :collision => :skip > > # Continue with your own manifest. > # ... > end > end > end > > I''m interested that you picked up on creating new generators; the > framework is rather well-hidden within Rails and lacks a good HOWTO. > > Do you find yourself systematically editing the code from > script/generate? Then write a generator to produce code in your own > style. > > jeremy > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >