Rakeのファイル分割
Rakefileがでかくなるとファイルを分割したくなる。
この時、rakelibというディレクトリーに*.rakeというファイルを作ると、自動で読み込んでくれる。
rakeのヘルプに書いている:
code:shell
% rake -h | rg rakelib
-R, --rakelibdir RAKELIBDIR, Auto-import any .rake files in RAKELIBDIR. (default is 'rakelib')
--rakelib
実験:
code:shell
% tree
.
├── Rakefile
└── rakelib
└── othertasks.rake
1 directory, 2 files
例えばRakefileには何も書かない:
code:shell
% cat Rakefile
require "rake/clean"
サブディレクトリーにファイルを置いてみる:
code:shell
% cat rakelib/othertasks.rake
desc "サブディレクトリーでのタスク"
task :task_in_subdir do |t|
puts t.name
end
タスクが認識される:
code:shell
% rake --tasks
rake task_in_subdir # サブディレクトリーでのタスク
勿論実行できる:
code:shell
% rake task_in_subdir
task_in_subdir