[Rake-devel] Using Rake as a Module instead of from the commandline

John Clayton john at fivesquaresoftware.com
Tue May 16 11:26:08 EDT 2006


Hey, thanks for the help.  I did play around with it yesterday, and  
it seemed basically workable to call application.run myself after  
adding the correct stuff to ARGV & ENV, and to even add some  
attributes to the class. But a bit messy, overall and probably prone  
to error (mine, of course ;-).

What V is proposing is precisely what I am needing and while I'm not  
the most experienced Ruby programmer, configuration objects work out  
pretty well in Java, even if they can seem a bit heavy-handed. The  
fact that you get separate documentation for the config object  
interface is nice.

But, it does seem in a way to have distributed your configuration  
interface across the command line parsing code in Application, and  
the config object, i.e., whatever parses the command line has to have  
some knowledge of how to create a config object out of that (or does  
it?), which essentially duplicates the state contained in the config  
object.  Another possible pattern might be to let a delegate or  
factory object handle the creation of the config object from a range  
of interfaces (:key => value, *args, ARGV, etc.) so knowledge of the  
config options if consolidated there, while also giving us the  
maximum in flexibility in terms of how we configure Application.

What you guys think?

P.S. Hours of Ant makes Rake addictive

John Clayton
---------------------------------------------------------------------
http://www.fivesquaresoftware.com
john at fivesquaresoftware.com
---------------------------------------------------------------------
CatSlapper - Manage and install multiple Tomcats



On May 16, 2006, at 12:54 AM, Damphyr wrote:

> Jim Weirich wrote:
>> John Clayton wrote:
>>> Hi,
>>>
>>> I have a project that is using Rake to do some build/deploy  
>>> tasks.  A
>>> framework we are using to accomplish this runs a rake command  
>>> line to
>>> get started.  But, it would be great for Rake to be able to use the
>>> same resources as the framework (logging, notifications, etc.).  I
>>> was thinking the way to accomplish this would be to load and
>>> configure Rake objects directly, instead of calling system(rake),  
>>> and
>>> run Rake that way so that our Rakefile could use resources loaded in
>>> the same interpreter.
>>>
>>> Am I all whacked in my approach?  Does anyone have other ideas?
>>
>> This makes sense.  Others have done stuff like this as well.
>>
>> Recent versions of Rake have moved a lot of the global definition  
>> stuff
>> into a module for better integration for situations like this.  It's
>> probably not perfect, so I would be interested in any feedback in  
>> this area.
>>
> I too want this kind of functionality. I have a test integration
> framework that brings together several of our in-house tools and  
> for the
> moment I'm calling rakefiles in a shell, which considering all my code
> is in Ruby is a bit of a shame.
> I guess the only thing that needs to be changed to allow this more
> easily, is the command line option handling.
> There should be a way to pass all the options to the Application  
> object
> without using the command line syntax.
> One solution is to be able to pass an OpenStruct to initialize and  
> check
> for nil in Application#handle_options (but I don't like it very much
> since it would mean you have to know all options by heart and the
> interface is defined in Application. It's not that it doesn't work,  
> it's
> that it is impractical when you want to provide default values for  
> some
> paramaters and for the documentation)
> Another would be to skip the ostruct and go directly for the
> :symbol=>value hash so used in Rails.
> A third option would be to wrap this ostruct/hash in a configuration
> object with accessor methods. This gives us an interface separately  
> from
> the Application which will look better in RDoc :) ).
> Anyway, the code in
>
> if __FILE__ == $0 then
>
> end
>
> would then do a few more things. Basically:
>
> params=parse_command_line(ARGV)
> validate_parameters(params)
>
> Rake::Application.new(params).run
> or even
> Rake::Application.new.run(params)
>
> Any comments?
> Cheers,
> V.-
> -- 
> http://www.braveworld.net/riva
>
> ____________________________________________________________________
> http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
> http://www.freemail.gr - free email service for the Greek-speaking.
> _______________________________________________
> Rake-devel mailing list
> Rake-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rake-devel




More information about the Rake-devel mailing list