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

Damphyr damphyr at freemail.gr
Tue May 16 03:54:04 EDT 2006


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.


More information about the Rake-devel mailing list