Same generator, multiple scopes

1 view
Skip to first unread message

Daniel N

unread,
Oct 22, 2007, 12:30:10 AM10/22/07
to RubiGen
I'm looking at changing the way that generators are working in Merb.
Merb wants to be db agnostic and so it would be nice to have model
generators etc play well.

atm we have scopes for the generator of
[:merb, :rspec/:test_unit]
and this works well for selecting the test stub to generate by having
merb define the test_unit and rspec generators with the same name.

What currently happens with model generators though is that each ORM
defines their own. They all work the same, but they are called
different things. So you have

ar_model, sequel_model, dm_model and the same for migrations. These
are all in the merb scope so they must be renamed for the individual
ORM. I don't like the pollution when I run a bare script/generate and
it reports all these different generators, and I sometimes have to do
that to remember what the generator is called.

What I would like to do is to include another scope. The ORM scope.
I would then define the scopes as:
[:data_mapper, :merb, :rspec]

Then in the merb gem, in :merb scope I want a merb_model generator.
This would generate a basic class and test as a default. If I then
define a merb_model generator in the :data_mapper scope in the
data_mapper gem, I want it to use that for merb_model instead since
it's listed first in the scope list.

I hope I'm making sense. To be more consise, I'd like to define
multiple scopes, and, in order of the declared scope, have it look for
a generator of the given name. If it finds one use that and stop
looking.

This would allow me to use
ruby script/generate merb_model

and depending on the scope provided I would get the correct model with
it falling back to the merb defined merb_model if no other scope
defines the merb_model generator.

Am I making sense?

Cheers
-Daniel

Nic Williams

unread,
Oct 22, 2007, 1:29:02 AM10/22/07
to rub...@googlegroups.com
Perhaps it could print a list of scopes that match, and you pick from a list (sounds like more work to implement, but might be better - means you don't have to care what order you write your scopes in)

Nic

http://drnicacademy.com - Ruby/Rails training around the world
http://drnicwilliams.com - Ruby/Rails/Javascript/Web2.0
skype: nicwilliams
(p) +61 412 002 126
(mail) PO Box 583, Ashgrove 4060, Queensland, Australia

Daniel N

unread,
Oct 22, 2007, 2:28:40 AM10/22/07
to rub...@googlegroups.com
On 10/22/07, Nic Williams <drnicw...@gmail.com> wrote:
Perhaps it could print a list of scopes that match, and you pick from a list (sounds like more work to implement, but might be better - means you don't have to care what order you write your scopes in)

Nic

If that works for the grand scheme.  For me, I just want to type it in and let it fly based on my scope preferences.  Perhaps there could be an option to choose between the two methods?

What do you think?

-Daniel

Nic Williams

unread,
Oct 22, 2007, 2:30:58 AM10/22/07
to rub...@googlegroups.com
Yeah, we'll need a "no user interaction" option (e.g. :force => true) for dependencies, anyway.
--
Dr Nic Williams

Daniel N

unread,
Nov 2, 2007, 1:02:08 PM11/2/07
to rub...@googlegroups.com
DrNic,

I've found the change that is required for this to work, but I haven't been able to work out the test for it.

http://pastie.textmate.org/private/bdirim9zt78njslcpxokla


The only change required is that .reverse at the end.  I've actually tried this out on a number of generators and it works no problem.  No error is thrown for having multiple generators of the same name.


Let me know what you think.


Cheers

-Daniel


Reply all
Reply to author
Forward
0 new messages