lib/folio/fileobject.rb in folio-0.2.0 vs lib/folio/fileobject.rb in folio-0.3.0

- old
+ new

@@ -1,28 +1,28 @@ require 'enumerator' require 'fileutils' -class Enumerator - alias_method :list, :to_a -end +#class Enumerator +# alias_method :list, :to_a +#end module Folio # = File Object # # Base class for all folio objects. - # + class FileObject Separator = ::File::Separator # Factory method. def self.[](*path) path = ::File.join(*path) - raise FileNotFound unless ::File.exist?(path) + raise FileNotFound, "#{path}" unless ::File.exist?(path) case ::File.ftype(path) when 'file' Document.new(path) when 'directory' @@ -43,27 +43,36 @@ end private def initialize(path) - raise FileNotFound unless ::File.exist?(path) - @relpath = path - @path = ::File.expand_path(path) + raise FileNotFound, "#{path}" unless ::File.exist?(path) + @path = ::File.expand_path(path) end public attr :path - attr :relpath + def ==(other) +#p @path, other.path + return false unless FileObject===other + @path == other.path + end + # This will alwasy be true, EXCEPT when # #rm, #delete or #unlink have been used. def exist? ::FileTest.exist?(path) end alias_method :exists?, :exist? + # Returns the parent directory object. + def parent + self.class[File.dirname(path)] + end + #-- # File Manipulation #++ def link(new) @@ -88,11 +97,10 @@ end alias_method :ln_sf, :symlink_force def rename(dest) ::File.rename(path, dest) - @relpath = dest @path = ::File.expand_path(dest) end alias_method :mv, :rename # how to handle --b/c it disappears? @@ -135,9 +143,10 @@ # Install file to destination path. def install(dest, mode=nil) util.install(path, dest, mode) end + # def touch util.touch(path) end # Status methods. These methods all access a cached