Using Rake across multiple files

Hi Everyone,

Bear with me here - I try to be descriptive right off the bat to spare
future questions :slight_smile:

I’m working on a tool that uses rake to call ruby methods.

A brief description of my setup:

File A: A shell file that calls rake (eg: From command line I can call
myprogram my_method 12345 and it would call rake mymethod[12345].

File B: A Rake file that requires File C. It has the Rake tasks defined
and then calls something like It also has
ClassB in it, which inherits from Class A which is in the required File

File C: A Ruby file with all of my underlying logic. This includes Class

I have this setup this way currently because we have various programs
using this - We install the original package which includes File A and
File C so that we can run the program from command line and interact
with the project we are working on at hand. We have to include File B in
the project, as it has project specific variables, and we also want the
option to override any methods in File C.

The issue I have with this setup is that to add a new command - it’s
slightly tedious, we need to add it to File A so that it can call the
rake task (Understandable and that’s fine), we need to add it to File C
so that they logic is there (Also understandable - where else are we
going to put it?), But I also have to explicitly declare the Rake task
in File B - for every project - which is a pain in the ass if there’s
ever a change. I tried moving the Rake tasks in File B to File C - but
then you have to keep pointing at ClassB, which inherits from ClassA in
order to make sure we can override methods if need be.

Just wondering if anyone has any advice on how to do this more cleanly,
or if there are more efficient and proper ways to do so with Ruby and


I would suggest taking a look at Jim W. ‘Power Rake’ presentation
Pay close attention to the portions regarding pathmap. You could use
to dynamically include all the files you need into your rake file.

Then, I would think about using a little metaprogramming to setup the
Rakefile with all the tasks you need.

something like this:

Given, there will have to be some additional code work for instance and
class level methods.