Creating a folder with the directory method
Sometimes, you will have to create folders with nesting. You can create files and folders with file tasks. If you need to create a folder tree, you can achieve this with the file tasks' definitions and their dependencies. The following is an example of this usage:
file 'my_gem' do |t| mkdir t.name end file 'my_gem/tests" => ['my_gem'] do |t| mkdir t.name end file 'my_gem/tests/fixtures" => ['my_gem/tests/fixtures'] do |t| mkdir t.name end
When you try to execute the my_gem/tests/fixtures
task, it will first call the dependent my_gem/tests
task and then the call will be passed to the my_gem
task. The tasks create folders with their name. Finally, we will have created a ready-to-use folder path, my_gem/tests/fixtures
.
Another way is to use the FileUtils#mkdir_p
method, which might be used in the task action or just in the Rakefile
context. However, this is not the Rake way. There is a special way to define folder tasks in the Rake language:...