require 'folio/fileobject' module Folio class Document < FileObject def intialize(path) super raise FileNotFound unless ::File.file?(@path) raise FileNotFound if ::File.symlink?(@path) end #-- # Polymorphism #++ def file? ; true ; end #-- # FileTest:: #++ def executable? ; ::FileTest.executable?(path) ; end def executable_real? ; ::FileTest.executable_real?(path) ; end #-- # File:: #++ def read ; ::File.read(path) ; end def readlines ; ::File.readlines(path) ; end # TODO: how to handle unkinking (b/c file no longer exists) def unlink ; ::File.unlink(path) ; end def delete ; ::File.delete(path) ; end #-- # File.open #++ def open(mode, &block) ::File.open(path, mode, &block) end def truncate(size) ::File.open(path, 'w'){|f| f.truncate(size)} end #-- # Can we handle other modes besides read this way? #++ #flock(mode) ; _file.flock(mode) ; end #def method_missing(s, *a, &b) # _file.send(s, *a, &b) #end #private #def _file ; @_file ||= ::File.new(path) ; end end end