Permalink
Browse files

add Pathname#copy_to

  • Loading branch information...
1 parent 77bbaae commit 667292e6812fc77071fd59ffcbd362609b798581 @quix committed Aug 9, 2009
Showing with 16 additions and 0 deletions.
  1. +6 −0 lib/quix/ext/pathname.rb
  2. +10 −0 test/test_pathname.rb
View
@@ -81,6 +81,12 @@ def binreplace(&block)
replace(BINARY_READ_FLAGS, BINARY_WRITE_FLAGS, &block)
end
+ def copy_to(dest, preserve = false)
+ require 'fileutils'
+ FileUtils.copy_entry(to_s, dest, preserve)
+ self.class.new(dest)
+ end
+
class << self
def join(*paths)
new File.join(*paths)
View
@@ -135,4 +135,14 @@ def test_initialize
assert_equal "a/b/c", Pathname("a\\b\\c").to_s
end
end
+
+ def test_copy_to
+ source, dest = %w[source dest].map { |f| Pathname(DATA_DIR) + f }
+ contents = "abab"
+ source.write(contents)
+ assert(!dest.exist?)
+ source.copy_to(dest)
+ assert contents, source.read
+ assert contents, dest.read
+ end
end

0 comments on commit 667292e

Please sign in to comment.