Hi - I have a simple problem, maybe you guys can help me come up with a
solution:
I'm looking for a way to let a user of my rails app execute a rake-task
by clicking on a link in a view.
Szenario:
I'm writing a rails-App that takes a given directory and analyzes any
ruby files in that directory. Since there already are quite a few tools
that gather information from ruby-sourcecode i don't feel like
re-inventing the wheel and i'd like to integrate some of those tools
into my app.
The "Metric-Fu"-Suite for example comes with all kinds of
Metric-Calculation tools that can be started with different rake-tasks
I.e. "rake metrics:reek" will start collecting info about "bad smells"
using the roodi-Toolset. It's also possible to pass parameters (or
define them in the rakefile) to tell reek which directories to parse for
sourcefiles.
For my project I would like to create a view where a user can add local
directories where sourcefiles are located, and select the metric tools
he wants to use to check his code (like reek, roodi, flog etc).
Is there any way to implement this?
I'd basically need to create a rake task with the given parameters and
than run it from my controller...
Just a guess, since I haven't ever had this situation but, rake files
are ruby files, you should be able to include them from any other ruby
file and execute the methods it has defined inside.
As I said, I haven't tried this, is just a guess.
Otherwise, you can always use a system call to execute system commands
(such as rake)
Finally got it to run using the "system call"-approach:
The trick to get it to run on my windows machine was using the "start"
command (that usually spawns a procell in a new shell). Why windows
executes the "dir" command without "start" but not the rake command is
beyond me, but at least now it is working:
Is rake a batch file in windows? That could explain this, I believe a
batch file cannot just be run, it needs a command shell to do it.
Whether it might explain other problems I do not know.
Is rake a batch file in windows? That could explain this, I believe a
batch file cannot just be run, it needs a command shell to do it.
Whether it might explain other problems I do not know.
Colin
That sounds reasonable. As a matter of fact there are two rake-files in
my ruby/bin directory, one of which is a batch file (the other one is
just called 'rake' with no suffix).
It seems like the rake.bat file starts a ruby command executing the
'rake'-File (which, when opened in notepad is just a regular ruby file
but has no extension)...