lib/folio/document.rb in folio-0.3.0 vs lib/folio/document.rb in folio-0.4.0
- old
+ new
@@ -6,20 +6,19 @@
#
# The Document class represents a FileObject.
#
class Document < FileObject
- def intialize(path)
- super
- raise FileNotFound unless ::File.file?(@path)
- raise FileNotFound if ::File.symlink?(@path)
+ #def intialize(path)
+ # super
+ #end
+
+ def assert_exists
+ raise FileNotFound.new(@path) unless ::File.file?(@path)
+ raise FileNotFound.new(@path) if ::File.symlink?(@path)
end
- #--
- # Polymorphism
- #++
-
#def file? ; true ; end
def document? ; true ; end
#--
# FileTest::
@@ -30,12 +29,14 @@
#--
# File::
#++
+ # Read file in as a string.
def read ; ::File.read(path) ; end
+ # Read file in as an array of lines.
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
@@ -54,15 +55,17 @@
# Replace contents of file with string.
def write(string)
::File.open(path, 'w'){|f| f.write(string)}
end
+
alias_method :<, :write # NOTE: Sure about this? It means no Comparable.
# Replace contents of file with string.
def append(string)
::File.open(path, 'a'){|f| f.write(string)}
end
+
alias_method :<<, :append
#--
# Can we handle other modes besides read this way?
#++