Add file modes. Replace magic values with constants.

This commit is contained in:
Scott Taylor 2009-09-30 02:45:48 -04:00
parent a34f8e8beb
commit 20eb3f238e
2 changed files with 11 additions and 2 deletions

View File

@ -2,6 +2,15 @@ module FakeFS
class File
PATH_SEPARATOR = '/'
MODES = [
READ_ONLY = "r",
READ_WRITE = "r+",
WRITE_ONLY = "w",
READ_WRITE_TRUNCATE = "w+",
APPEND_WRITE_ONLY = "a",
APPEND_READ_WRITE = "a+"
]
def self.extname(path)
RealFile.extname(path)
end
@ -69,7 +78,7 @@ module FakeFS
FileSystem.find(symlink.target).to_s
end
def self.open(path, mode='r', perm = 0644)
def self.open(path, mode=READ_ONLY, perm = 0644)
if block_given?
yield new(path, mode, perm)
else

View File

@ -54,7 +54,7 @@ module FakeFS
files.each do |f|
if RealFile.file?(f)
FileUtils.mkdir_p(File.dirname(f))
File.open(f, 'w') do |g|
File.open(f, File::WRITE_ONLY) do |g|
g.print RealFile.open(f){|h| h.read }
end
elsif RealFile.directory?(f)