Splitting up gator and gator-as3

22 views
Skip to first unread message

devboy

unread,
Jul 10, 2011, 3:55:34 PM7/10/11
to gator-g...@googlegroups.com
Today I split the example ActionScript3 generators I had in the core gator library into a separate library called gator-as3.
Both libraries are available on rubygems:

$ gem install gator --pre
and
$ gem install gator-as3 --pre

This has two purposes: 
First it makes no sense to have AS3 generators in gator when the goal is to make this an abstract tool for multiple languages.
Second it demonstrates the process of setting up your own plugin or set of generators.

While the (custom) generator part is still experimental and could use some more developer-friendly APIs like introducing a Generator & TestGenerator type,
it will hopefully indicate if this current setup makes sense and is easy to grasp.

This does not affect the project templates as they are still first-class citizens in the gator library.
Gator-as3 on the other hand is not a first-class citizen and must be loaded in the file "gator.rb" in your project's base directory.
To load in the as3-generators you would need to have something like the following:

# This will load the as3 generator collection
require "gator/as3/generators"

project Gator::Project::ProjectBase.new
project.name = "MyProject"
project.options[:authors] = ["devboy"]
project.layout[:source,:main,:as3] = "src"
project.layout[:source,:test,:as3] = "test" 

To be able to load in generators & commands like this on a per project basis makes gator really powerful 
as we are now able to switch libraries around while our command-line calls will stay the same.
Let's assume we want to use flexunit4 in this project and therefore use flexunit4 test generators,
we can now do this by just loading the flexunit4 test generator collection.
Let's add this line to the "gator.rb":

require "gator/as3/generators/test/flexunit4"

This will add the test generator collection to the as3 generator collection which results in the following command-line call to create a Class UnitTest:

$ gator generate as3 test klass org.devboy.MyClassTest

Just to make it clear here is how one would generate a normal Class in gator:

$ gator generate as3 klass org.devboy.MyClassTest 

Now let's say you're on another project which uses ASUnit4, no problem, we just load the ASUnit4 test generator collection instead of the flexunit one:

require "gator/as3/generators/test/asunit4"

Creating a Class UnitTest will still work in the same way as we are used to:

$ gator generate as3 test klass org.devboy.MyClassTest

As you can see this will bring a lot of flexibility with it.
Apart from having different test frameworks you might have seen that I used "test klass" to generate the UnitTests.
This means we can also have multiple test-generators in a test-generator-collection (therefore the name collection :P).

Let's say we want to have a custom generator for Event classes, 
we could create one and add it to generator collection so that we can generate Event classes from templates like this:

$ gator generate as3 event org.devboy.MyEvent

Now we would also like to have a custom UnitTest for our event, we would create a test-generator in the test-generator-collection and give the same name as our "normal" generator.

$ gator generate as3 test event org.devboy.MyEvent

When making it a standard of using the same names for our generators and its counterpart test-generator gator could look up automatically if it comes across a test-generator to generate the test, or vice versa, generate the class for a unit-test.
If it can't find an appropriate counter-part it would fallback to a basic class or class-test generator.

This can then also be used to make third party plugins ship with their own set test generators.
For example: A robotlegs plugin would ship with a command-generator and a CommandUnitTest Generator,
you would have everything out of the box, but would still be able to write your own and load those in with no change on the command-line interface.

I think I am gonna stop here, and hope someone takes the time to read this.

Would love some feedback! :)

Cheers  

devboy

unread,
Jul 10, 2011, 4:13:08 PM7/10/11
to gator-g...@googlegroups.com
It would be an idea to also make this a setting in the "gator.rb" file,
something like:

project.test_framework = :asunit4


Reply all
Reply to author
Forward
0 new messages