Directory DSL as task #67

Merged
merged 3 commits into from Oct 23, 2012
Jump to file or symbol
Failed to load files and symbols.
+23 −3
Split
@@ -52,8 +52,8 @@ def file(*args, &block)
# Declare a file creation task.
# (Mainly used for the directory command).
- def file_create(args, &block)
- Rake::FileCreationTask.define_task(args, &block)
+ def file_create(*args, &block)
+ Rake::FileCreationTask.define_task(*args, &block)
end
# Declare a set of files tasks to create the given directories on
@@ -62,12 +62,15 @@ def file_create(args, &block)
# Example:
# directory "testdata/doc"
#
- def directory(dir)
+ def directory(*args, &block)
+ ret = file_create(*args, &block)
+ dir, _ = *Rake.application.resolve_args(args)
Rake.each_dir_parent(dir) do |d|
file_create d do |t|
mkdir_p t.name if ! File.exist?(t.name)
end
end
+ ret
end
# Declare a task that performs its prerequisites in
View
@@ -1,4 +1,5 @@
require 'rubygems'
+$:.unshift File.expand_path('../../lib', __FILE__)
begin
gem 'minitest'
@@ -43,4 +43,20 @@ def test_directory_win32
refute File.exist?('c:/a/b/c')
end
end
+
+ def test_can_use_blocks
+ runlist = []
+
+ t1 = directory("a/b/c" => :t2) { |t| runlist << t.name }
+ t2 = task(:t2) { |t| runlist << t.name }
+
+ verbose(false) {
+ t1.invoke
+ }
+
+ assert_equal Task["a/b/c"], t1
+ assert_equal FileCreationTask, Task["a/b/c"].class
+ assert_equal ["t2", "a/b/c"], runlist
+ assert File.directory?("a/b/c")
+ end
end