[clue] Rake (Ruby) question posted... any experts here?

Lorin Ricker Lorin at RickerNet.us
Wed Dec 7 20:49:21 MST 2011

Nope... er, yup, Dave, the Rake/Ruby syntax is legit, this I know for 
sure.  It's all happily gobbled & parsed by the Ruby interpreter, and 
I've been studying the language for months now.  I know it "looks 
strange" to a coder (like me) who's been used to "execution flow" 
languages (like Pascal, C, etc.) for decades... but this is the way 
Ruby's coded.

And a Rakefile is what's called a "domain specific language" (or DSL), 
an adaptation (extension) of the Ruby language to fit a specific 
application domain or problem -- Rake's "domain" is task automation, 
like make or ant.

Addressing your own questions:

tarDir = File.join BUPDIR, tarDirSuffix

"File.join" is a method call, with arguments BUPDIR and tarDirSuffix, 
which joins the contents of these variables (objects) in directory/path 
syntax, and assigns the resultant string to tarDir (e.g., tarDir = 
"/home/lorin/backups/loginstash" ...yes, my code walkthrough testing 
verifies that this all works).

directory tarDir

This is a separate statement, and is method call (directory) is a rake 
built-in which tests the existence of a directory path, and if it 
doesn't exist, creates it.

desc "Backup #{fn} to .../#{tarDirSuffix}"

is an internal documentation attribute which attaches to the following 
task declaration -- these things print/echo out when the rake-invoking 
com-line says something like "$ rake -T"  ...The #{var} thingies are 
string-substitutions, like echo "variable is ${var}" in bash.

file tar => [src] do |t|

This is a call (message) to the file object to declare one or more "file 
tasks" using a hash-syntax to pass arguments (tar => [src]) and a block 
parameter (the "|t|").  See any good Ruby primer text, which will also 
tell you that the parentheses which usually surround "function call 
argument list" in other languages can be omitted in Ruby when the 
construct is non-ambiguous (and it is so here)...

More to the point, the "file tar =>..." method forms a "dependency 
relationship" between a source file (instances of "src") and a target 
file (instances of "tar").  Don't be fooled by the unconventional 
syntax... This is a legal and correct "call" to this method ("file"), 
and I've been staring at the Rake source code to prove it (to myself).

I do agree with you that "It (and the lines after) doesn't seem to 
run... Is that a hint?"  Well, no.  But I agree that, to someone who's 
new to Ruby, things indeed don't "look like they run."  Ruby is a very 
*declarative* language... Although some things "look normal" and you can 
see the "execution trace" of a group of statements (how they'd run), 
other parts are pretty non-procedural, and don't "look like how they'll 

No, my problem with this code is not in the syntax... it's much more 
subtle than that.  I know I'm missing something, but it's not, I think, 
in the (legal, well-formed) Ruby statements themselves... It's "under 
the covers", if that makes sense.  I've gone over this code for hours, 
and have validated each and every Ruby syntactical element -- although 
clearly I may (probably have) missed something essential due to my 
unfamiliarity with the Rake idioms.  Much of this is cribbed 
(shamelessly copied and adapted) from other Rake examples (I give a 
webpage reference to the core stuff I've adapted in the problem post);
I'm still missing something which is, again, "under the covers" and not 
(yet) obvious to a Rake novice like me.

But thanks for giving it a shot!...
   -- Lorin

On 01/-10/-28163 12:59 PM, David L. Anselmi wrote:
> Lorin Ricker wrote:
>> Are there any Rake/Ruby experts here in CLUE who'd be willing to look at
>> the above posting and give my question/problem a shot?
> I don't know anything about rake so I have some questions about the
> code. If they're worth answering maybe that will help.
> tarDir = File.join BUPDIR, tarDirSuffix
> directory tarDir
> What's "directory tarDir" and why does it come after the assignment?
> desc "Backup #{fn} to .../#{tarDirSuffix}"
> What does this do? It (and the lines after) doesn't seem to run. Is that
> a hint?
> file tar => [src] do |t|
> This seems badly formed. tar seems to be a variable containing the full
> path to the backup file. src seems to be a variable containing the path
> to the source file. What's file? Does it make sense to say "file => [src]"?
> So I think your problem is not in the "is the file newer" logic but in
> your "file tar ..." loop.
> HTH,
> Dave

More information about the clue mailing list