0

I am watching a Peepcode screencast Play by Play: Jim Weirich.

He executes a rake task that appears to pass the final task name as an option.

rake -g projec:ruby:demo

See how the task :demo creates a "demo" folder. How was this done?

EDIT:

Thanks, Alex.Bullard.

So with something like this:

namespace :project do
    namespace :ruby do
        rule "" do |t|
            puts t.name
        end
    end
end

Running $ rake project:ruby:demo outputs project:ruby:demo.

Do I have to t.name.split(":") or is there a way to grab just that final name?

seanomlor
  • 973
  • 1
  • 10
  • 23
  • There's not enough context to understand what's going on. What was the current directory when `rake` was run? From that snippet, it's not clear that any directory is being created. – Kelvin Mar 29 '13 at 21:24
  • Good point. In fact, watching this part again, I think he may have a :demo task defined and just happen to be in a demo folder. In any case, I learned a new trick from @Alex.Bullard below, so that's cool. :) – seanomlor Mar 29 '13 at 21:57

1 Answers1

1

If you define a task like this:

  namespace :test do
    rule "" do |t|
      # t.name is 'test::[whatever]"
    end
  end

Then the "" task will act as a catchall and you can use its name as an argument for whatever you want

Alex.Bullard
  • 5,533
  • 2
  • 25
  • 32
  • Yes! Thanks. Now do I have to `t.name.split(":")`, or is there a built-in way to grab just that last name? (I've updated my question above with more details). – seanomlor Mar 29 '13 at 21:47