"耙路"实际上做了什么?

dje*_*lin 1 ruby rake ruby-on-rails

在一个新的(ish)rails项目中,Rakefile看起来像这样:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Blog::Application.load_tasks
Run Code Online (Sandbox Code Playgroud)

然后rake routes产生以下输出:

cpe-74-72-73-47:rails-blog-example djechlin$ rake routes
home_index GET /home/index(.:format) home#index
      root     /                     home#index
Run Code Online (Sandbox Code Playgroud)

我不明白它是如何rake工作的,以便它可以到达路由文件或路由任务.根据命令行用法文档,rake调用为

rake [options ...]  [VAR=VALUE ...]  [targets ...]
Run Code Online (Sandbox Code Playgroud)

但该页面没有解释目标是什么.我假设从这个文件rake直接调用routes.rb,这Rakefile是没有关系的,但我根本无法确认.

Ank*_*itG 6

Rakefile包含可执行的Ruby代码.在Rakefile中允许任何合法的ruby脚本.

当你触发时,rake routes 你调用这段Ruby代码.