On Wed, Apr 13, 2011 at 9:18 AM, Santosh <[email protected]> wrote:
> Hi,
> does anyone know how one can reference the task being executed and get
> its name in the Rakefile. For example, I want this:
>
>
> puts "You chose the task: " + taskname
>
> task :egg do
> puts " 1 egg "
> end
>
> task :milk do
> puts " 1 glass milk "
> end
>
>
> Depending on the task name, I want to do load certain time consuming
> things before the task is executed. Any ideas?
>
Hi Santosh,
If your tasks are inside of a namespace you already know which one is being
called. It would not be hard to pass the name of the task to private
function outside the namespace that will do some addition work for you. Here
is a simple example of what I'm talking about.
namespace :grocery do
task :egg do
shop_list("egg")
puts " 1 egg "
end
task :milk do
shop_list("milk")
puts " 1 glass milk "
end
end
private
def shop_list(item)
puts "You are looking for #{item}"
end
Let me know if this is not what you are looking for.
B.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.