Is there a "method_missing" for rake tasks?
Asked Answered
S

1

11

If my Rakefile does not find a task with a particular name, I'd like rake to instead create a new task by that name according to certain rules, if a file with the missing task name exists. But if it doesn't, I want to fall back to the default ("Don't know how to build task 'foo'!").

In short, is there a method_missing for Rake?

Seem answered 23/4, 2010 at 15:17 Comment(1)
I'd love to know how to do this if that's possible. I don't think method_missing is really the right thing to look for, though. Rake is really looking up names, not methods, for tasks. It would be more appropriate if there were something like a task_missing hook that you could override, but a cursory inspection of the code doesn't show anything like that.Arista
H
12

I haven't tried it, but a quick search revealed this.

If you define a rule with an empty string, you can catch any task that hasn’t been defined elsewhere. This makes it easy to dynamically create rake tasks. Essentially, this is method_missing for rake!

rule "" do |t|
  t.name 
  # ... do something with the name of the task  
end
Hicks answered 28/5, 2010 at 12:30 Comment(1)
This works great. Except that I have no access to anything in the /lib folder from a rule.Concealment

© 2022 - 2024 — McMap. All rights reserved.