From 28e0dd343fbf402d58d4b28cd22787e83b9105a8 Mon Sep 17 00:00:00 2001
From: Dominic Sisneros <dsisnero@gmail.com>
Date: Tue, 18 May 2010 16:49:24 -0600
Subject: [PATCH] added path (Pathname) to FileTask to make it easier to create files

---
 lib/rake/dsl_definition.rb     |   11 ++++++-----
 lib/rake/file_creation_task.rb |    2 +-
 lib/rake/file_task.rb          |   15 ++++++++++++---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/lib/rake/dsl_definition.rb b/lib/rake/dsl_definition.rb
index 2c01476..4fa91c1 100644
--- a/lib/rake/dsl_definition.rb
+++ b/lib/rake/dsl_definition.rb
@@ -1,6 +1,6 @@
 # Rake DSL functions.
 require 'rake/file_utils_ext'
-
+require 'pathname'
 module Rake
   module DSL
 
@@ -27,9 +27,9 @@ module Rake
     # Declare a file task.
     #
     # Example:
-    #   file "config.cfg" => ["config.template"] do
-    #     open("config.cfg", "w") do |outfile|
-    #       open("config.template") do |infile|
+    #   file "config.cfg" => ["config.template"] do |t|
+    #     t.path.open("w") do |outfile|
+    #       t.prerequisites[0].path.open("config.template") do |infile|
     #         while line = infile.gets
     #           outfile.puts line
     #         end
@@ -54,7 +54,8 @@ module Rake
     #   directory "testdata/doc"
     #
     def directory(dir)
-      Rake.each_dir_parent(dir) do |d|
+      path = Pathname.new(dir)
+      path.ascend do |d|      
         file_create d do |t|
           mkdir_p t.name if ! File.exist?(t.name)
         end
diff --git a/lib/rake/file_creation_task.rb b/lib/rake/file_creation_task.rb
index c87e219..32a0272 100644
--- a/lib/rake/file_creation_task.rb
+++ b/lib/rake/file_creation_task.rb
@@ -11,7 +11,7 @@ module Rake
   class FileCreationTask < FileTask
     # Is this file task needed?  Yes if it doesn't exist.
     def needed?
-      ! File.exist?(name)
+      ! path.exist?
     end
 
     # Time stamp for file creation task.  This time stamp is earlier
diff --git a/lib/rake/file_task.rb b/lib/rake/file_task.rb
index 78902a8..e821f78 100644
--- a/lib/rake/file_task.rb
+++ b/lib/rake/file_task.rb
@@ -1,5 +1,6 @@
 require 'rake/task.rb'
 require 'rake/early_time'
+require 'pathname'
 
 module Rake
   # #########################################################################
@@ -10,16 +11,24 @@ module Rake
   #
   class FileTask < Task
 
+    attr_reader :path
+
+    def initialize(*args)
+      super
+      @path = Pathname.new(name)
+    end
+    
+
     # Is this file task needed?  Yes if it doesn't exist, or if its time stamp
     # is out of date.
     def needed?
-      ! File.exist?(name) || out_of_date?(timestamp)
+      ! @path.exist? || out_of_date?(timestamp)      
     end
 
     # Time stamp for file task.
     def timestamp
-      if File.exist?(name)
-        File.mtime(name.to_s)
+      if @path.exist?
+        @path.mtime
       else
         Rake::EARLY
       end
-- 
1.7.0.2.msysgit.0

