When I need to alias some task's name, how should I do it?
For example, how do I turn the task name:
rake db:table
rake db:create
rake db:schema
rake db:migration
to:
rake db:t
rake db:c
rake db:s
rake db:m
Editing after getting the answer:
def alias_task(tasks)
tasks.each do |new_name, old_name|
task new_name, [*Rake.application[old_name].arg_names] => [old_name]
end
end
alias_task [
[:ds, :db_schema],
[:dc, :db_create],
[:dr, :db_remove]
]
Here is some code someone wrote to do it: https://gist.github.com/232966
Why do you need an alias? You may introduce a new task without any code, but with a prerequisite to the original task.
This can be combined with parameters:
To avoid to search for the parameters names you may read the parameters with
arg_names
:Combine it to a
define_alias_task
-method:Tested with ruby 1.9.1 and rake-0.8.7.
Hmmm, well, I see that's more or less exactly the same solution RyanTM already posted some hours ago.