File Object

Base class for all folio objects.

Methods
Constants
Separator = ::File::Separator
Attributes
[R] path
[R] relpath
Public Class methods
[](*path)

Factory method.

# File lib/folio/fileobject.rb, line 13
    def self.[](*path)
      path = ::File.join(*path)

      raise FileNotFound unless ::File.exist?(path)

      case ::File.ftype(path)
      when 'file'
        Document.new(path)
      when 'directory'
        Directory.new(path)
      when 'link'
        Link.new(path)
      when 'characterSpecial'
        CharacterDevice.new(path)
      when 'blockSpecial'
        BlockDevice.new(path)
      when 'socket'
        raise TypeError # Socket.new(path) ?
      when 'fifo'
        raise TypeError # Pipe?
      else # 'unknown'
        raise TypeError
      end
    end
new(path)
# File lib/folio/fileobject.rb, line 40
    def initialize(path)
      raise FileNotFound unless ::File.exist?(path)
      @relpath = path
      @path    = ::File.expand_path(path)
    end
Public Instance methods
<=>(other)
# File lib/folio/fileobject.rb, line 225
    def <=>(other)
      path <=> other.to_s
    end
==(other)
# File lib/folio/fileobject.rb, line 229
    def ==(other)
      path == other.path
    end
atime()
# File lib/folio/fileobject.rb, line 159
    def atime               ; stat.atime             ; end
basename()
# File lib/folio/fileobject.rb, line 180
    def basename            ; ::File.basename(path)              ; end
blockdev?()
# File lib/folio/fileobject.rb, line 154
    def blockdev?           ; stat.blockdev?         ; end
chardev?()
# File lib/folio/fileobject.rb, line 155
    def chardev?            ; stat.chardev?          ; end
chmod(mode)
# File lib/folio/fileobject.rb, line 105
    def chmod(mode)
      ::File.chmod(mode, path)
    end
chown(user, group)
# File lib/folio/fileobject.rb, line 109
    def chown(user, group)
      ::File.chown(user, group, path)
    end
cp(dest)

Copy file to destination path.

# File lib/folio/fileobject.rb, line 124
    def cp(dest)
      util.cp(path, dest)
    end
ctime()
# File lib/folio/fileobject.rb, line 160
    def ctime               ; stat.ctime             ; end
delete()

Alias for unlink

delete_force()

Alias for unlink_force

directory?()
# File lib/folio/fileobject.rb, line 153
    def directory?          ; stat.directory?        ; end
dirname()
# File lib/folio/fileobject.rb, line 181
    def dirname             ; ::File.dirname(path)               ; end
exist?()

This will alwasy be true, EXCEPT when rm, delete or unlink have been used.

This method is also aliased as exists?
# File lib/folio/fileobject.rb, line 53
    def exist?
      ::FileTest.exist?(path)
    end
exists?()

Alias for exist?

extname()
# File lib/folio/fileobject.rb, line 182
    def extname             ; ::File.extname(path)               ; end
file?()
# File lib/folio/fileobject.rb, line 152
    def file?               ; stat.file?             ; end
fnmatch(pattern, flags=0)
This method is also aliased as fnmatch?
# File lib/folio/fileobject.rb, line 209
    def fnmatch(pattern, flags=0)
      ::File.fnmatch(path, pattern, flags)
    end
fnmatch?(pattern, flags=0)

Alias for fnmatch

grpowned?()
# File lib/folio/fileobject.rb, line 161
    def grpowned?           ; stat.grpowned?         ; end
identical?()
# File lib/folio/fileobject.rb, line 162
    def identical?          ; stat.identical?        ; end
inspect()

Inspect returns the path string relative to the current working directory.

# File lib/folio/fileobject.rb, line 220
    def inspect; "#{relative}"; end
install(dest, mode=nil)

Install file to destination path.

# File lib/folio/fileobject.rb, line 129
    def install(dest, mode=nil)
      util.install(path, dest, mode)
    end
link(new)
This method is also aliased as ln
# File lib/folio/fileobject.rb, line 62
    def link(new)
      ::File.ln(path, new)
    end
link_force(new)
This method is also aliased as ln_f
# File lib/folio/fileobject.rb, line 67
    def link_force(new)
      ::File.remove(new)
      link(new)
    end
ln(new)

Alias for link

ln_f(new)

Alias for link_force

ln_s(new)

Alias for symlink

ln_sf(new)

Alias for symlink_force

mtime()
# File lib/folio/fileobject.rb, line 163
    def mtime               ; stat.mtime             ; end
mv(dest)

Alias for rename

owned?()
# File lib/folio/fileobject.rb, line 164
    def owned?              ; stat.owned?            ; end
pipe?()
# File lib/folio/fileobject.rb, line 157
    def pipe?               ; stat.pipe?             ; end
readable?()
# File lib/folio/fileobject.rb, line 165
    def readable?           ; stat.readable?         ; end
readable_real?()
# File lib/folio/fileobject.rb, line 166
    def readable_real?      ; stat.readable_real     ; end
relative()

Gives path relative to current working directory. If current is below path one step then it uses ’..’, further below and it returns the full path.

# File lib/folio/fileobject.rb, line 190
    def relative
      pwd = Dir.pwd
      pth = path
      if pth.index(pwd) == 0
        r = pth[pwd.size+1..-1]
        r = '.' unless r
        return r
      else
        pwd = File.dirname(pwd)
        if pth.index(pwd) == 0
          r = pth[pwd.size+1..-1]
          return '..' unless r
          return File.join('..', r)
        else
          pth
        end
      end
    end
rename(dest)
This method is also aliased as mv
# File lib/folio/fileobject.rb, line 84
    def rename(dest)
      ::File.rename(path, dest)
      @relpath = dest
      @path = ::File.expand_path(dest)
    end
restat()

Refresh status cache.

This method is also aliased as stat!
# File lib/folio/fileobject.rb, line 147
    def restat
      @stat = File.stat(path)
    end
rm()

Alias for unlink

rm_f()

Alias for unlink_force

setgid?()
# File lib/folio/fileobject.rb, line 167
    def setgid?             ; stat.setgid?           ; end
setuid?()
# File lib/folio/fileobject.rb, line 168
    def setuid?             ; stat.setuid?           ; end
size()
# File lib/folio/fileobject.rb, line 169
    def size                ; stat.size              ; end
size?()
# File lib/folio/fileobject.rb, line 170
    def size?               ; stat.size?             ; end
socket?()
# File lib/folio/fileobject.rb, line 156
    def socket?             ; stat.socket?           ; end
split()

TODO: I don‘t like the name of this.

# File lib/folio/fileobject.rb, line 185
    def split               ; ::File.split(path)                 ; end
stat()

Get stat and cache it.

# File lib/folio/fileobject.rb, line 142
    def stat
      @stat ||= File.stat(path)
    end
stat!()

Alias for restat

sticky?()
# File lib/folio/fileobject.rb, line 171
    def sticky?             ; stat.sticky?           ; end
symlink(new)
This method is also aliased as ln_s
# File lib/folio/fileobject.rb, line 73
    def symlink(new)
      ::File.symlink(path, new)
    end
symlink_force(new)
This method is also aliased as ln_sf
# File lib/folio/fileobject.rb, line 78
    def symlink_force(new)
      ::File.remove(new)
      symlink(new)
    end
to_s()

Returns the path string.

# File lib/folio/fileobject.rb, line 223
    def to_s ; path ; end
touch()
# File lib/folio/fileobject.rb, line 133
    def touch
      util.touch(path)
    end
unlink()

how to handle —b/c it disappears?

This method is also aliased as delete rm
# File lib/folio/fileobject.rb, line 92
    def unlink
      ::File.delete(path)
    end
unlink_force()
This method is also aliased as delete_force rm_f
# File lib/folio/fileobject.rb, line 98
    def unlink_force
      ::File.remove(new)
      unlink(path)
    end
utime(atime, mtime)
# File lib/folio/fileobject.rb, line 113
    def utime(atime, mtime)
      ::File.utime(atime, mtime, path)
    end
writable?()
# File lib/folio/fileobject.rb, line 172
    def writable?           ; stat.writable?         ; end
writable_real?()
# File lib/folio/fileobject.rb, line 173
    def writable_real?      ; stat.writable_real?    ; end
zero?()
# File lib/folio/fileobject.rb, line 174
    def zero?               ; stat.zero?             ; end