Skip to content

Commit

Permalink
handle for a filesytem file object should be an attr_accessor so, whe…
Browse files Browse the repository at this point in the history
…n all else fails, one can have access to the file handle
  • Loading branch information
Jacob Perkins committed Feb 27, 2011
1 parent 3105dda commit 993ec97
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/swineherd/filesystem/localfilesystem.rb
@@ -1,83 +1,83 @@
require 'fileutils'
module Swineherd

class LocalFileSystem

include Swineherd::BaseFileSystem

def initialize *args
end

def open path, mode="r", &blk
return LocalFile.new path, mode, &blk
end

def rm path
FileUtils.rm_r path
end

def exists? path
File.exists?(path)
end

def mv srcpath, dstpath
FileUtils.mv(srcpath,dstpath)
end

def cp srcpath, dstpath
FileUtils.cp_r(srcpath,dstpath)
end

def mkpath path
FileUtils.mkpath path
end

def type path
case
when File.symlink?(path) then
return "symlink"
when File.directory?(path) then
return "directory"
when File.file?(path) then
return "file"
return "file"
end
"unknown"
end

def entries dirpath
return unless (type(dirpath) == "directory")
Dir.entries(dirpath)
end

class LocalFile
attr_accessor :path, :scheme, :mode
attr_accessor :path, :scheme, :handle, :mode

def initialize path, mode="r", &blk
@path = path
@mode = mode
@handle = File.open(path,mode,&blk)
end

def open path, mode="r", &blk
initialize(path,mode,&blk)
end

def read
@handle.read
end

def readline
@handle.gets
end

def write string
@handle.write(string)
end

def close
@handle.close
end
end

end
end

0 comments on commit 993ec97

Please sign in to comment.