开发者

Is there a "method_missing" for rake tasks?

开发者 https://www.devze.com 2022-12-28 11:50 出处:网络
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 accordi开发者_开发问答ng to certain rules, if a file with the missing task name exi

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 accordi开发者_开发问答ng 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消