forked from alienrobotwizard/swineherd
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle for a filesytem file object should be an attr_accessor so, whe…
…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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |