putting component generators under lib?

2 views
Skip to first unread message

NolMan

unread,
Oct 24, 2008, 3:55:40 PM10/24/08
to RubiGen
Hey all,

I was wondering how one would go about moving component generators to
be under lib and to still be included in my app_generator's script/
generate commands. I suspect it done via m.dependency but I am not
sure of the syntax to achieve this. Any assistance would be
appreciated.

Cheers,
-Nolan

Dr Nic Williams

unread,
Oct 24, 2008, 4:20:00 PM10/24/08
to rub...@googlegroups.com
The reason to put them in folders xxx_generators/yyy is that this is how RubiGen finds them within install gems. Rails is also patched to look for rails_generators/yyy for its generators.

Nic
--
Dr Nic Williams
Mocra - Premier iPhone and Ruby on Rails Consultants
w - http://mocra.com
e - dr...@mocra.com
p - +61 412 002 126 or +61 7 3102 3237
skype - nicwilliams

nolan evans

unread,
Oct 24, 2008, 5:49:23 PM10/24/08
to rub...@googlegroups.com
Hey Nic, thanks for the quick reply.

That makes sense, however as the generators we are making are pretty specific to our application and we don't really worry about using them in rails or other applications.  Pointing to a app_generator under lib is pretty straight forward, just change the Rubigen source in the bin.  Is there a way to get the generated script/generate file to point at our app specific path source without generating our own script/generate?

Cheers,
-Nolan

Dr Nic Williams

unread,
Oct 24, 2008, 7:08:56 PM10/24/08
to rub...@googlegroups.com
Yes you can put the generator anywhere and get the script/generate code to explicitly point to it. We use this for the test framework.

The class is RubiGen::PathSource

See the run_generator test helper as an example. Something like:

source = PathSource.new(:local, File.join(File.dirname(__FILE__), '../path/to/generator/parent/folder)

and then set everything up with:

      RubiGen::Base.reset_sources
      RubiGen::Base.prepend_sources(source)

Then run the generator with:

      RubiGen::Base.instance(name, params, options)

This way you can get your code to invoke a local generator.

Nic
Reply all
Reply to author
Forward
0 new messages