From: Dick Davies Date: 2008-04-15T00:02:30+09:00 Subject: Rake : conditional logic based on namespaces? ------=_Part_8130_19218030.1208185348137 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all I've got a Rakefile with 2 groups of commands (split into namespaces). One namespace ('rake show:foo') prints a string, the other 'backticks' it ("rake run:foo"'). The same functionality is duplicated in each namespace, so much that the code smells to high heaven - I'm in danger of 'show' and 'do' getting out of step. An example might help: ------------------------------------------------------------------------------- require 'rake' ls = 'ls /tmp' date = 'date' # show commands namespace :show do desc 'show command to list /tmp' task :ls do puts ls end desc 'show command to print date' task :date do puts date end end desc 'show commands' task :show => ['show:ls', 'show:date'] # run command namespace :run do desc 'list /tmp' task :ls do puts `#{ls}` end desc 'print date' task :date do puts `#{date}` end end desc 'run commands' task :run => ['run:ls', 'run:date'] ------------------------------------------------------------------------------- There must be someway to prevent duplicating the actual commands to run (which are a lot more convoluted in reality) - any ideas how? Thanks a lot. -- Rasputnik :: Jack of All Trades - Master of Nuns http://number9.hellooperator.net/ ------=_Part_8130_19218030.1208185348137 Content-Type: application/octet-stream; name=Rakefile Content-Transfer-Encoding: base64 X-Attachment-Id: f_ff167mj90 Content-Disposition: attachment; filename=Rakefile ICAgcmVxdWlyZSAncmFrZScKICAgCiAgIGxzID0gJ2xzIC90bXAnCiAgIGRhdGUgPSAnZGF0ZScK ICAgCiAgICMgc2hvdyBjb21tYW5kcyB3ZSBwbGFuIHRvIHJ1bgogICBuYW1lc3BhY2UgOnNob3cg ZG8KICAgICAgIGRlc2MgJ3Nob3cgY29tbWFuZCB0byBsaXN0IC90bXAnCiAgICAgICB0YXNrIDps cyBkbwogICAgICAgICAgIHB1dHMgbHMKICAgICAgIGVuZAogICAgICAgCiAgICAgICBkZXNjICdz aG93IGNvbW1hbmQgdG8gcHJpbnQgZGF0ZScKICAgICAgIHRhc2sgOmRhdGUgZG8KICAgICAgICAg ICBwdXRzIGRhdGUKICAgICAgIGVuZAogICBlbmQKICAgICAgIAogICBkZXNjICdzaG93IGNvbW1h bmRzJwogICB0YXNrIDpzaG93ID0+IFsnc2hvdzpscycsICdzaG93OmRhdGUnXQogICAKICAgIyBy dW4gY29tbWFuZAogICBuYW1lc3BhY2UgOnJ1biBkbwogICAgICAgZGVzYyAnbGlzdCAvdG1wJwog ICAgICAgdGFzayA6bHMgZG8KICAgICAgICAgICBwdXRzIGAje2xzfWAKICAgICAgIGVuZAogICAg ICAgCiAgICAgICBkZXNjICdwcmludCBkYXRlJwogICAgICAgdGFzayA6ZGF0ZSBkbwogICAgICAg ICAgIHB1dHMgYCN7ZGF0ZX1gCiAgICAgICBlbmQKICAgZW5kCiAgIAogICBkZXNjICdydW4gY29t bWFuZHMnCiAgIHRhc2sgOnJ1biA9PiBbJ3J1bjpscycsICdydW46ZGF0ZSddCg== ------=_Part_8130_19218030.1208185348137--