File Object
Base class for all folio objects.
- <=>
- ==
- []
- atime
- basename
- blockdev?
- chardev?
- chmod
- chown
- cp
- ctime
- delete
- delete_force
- directory?
- dirname
- exist?
- exists?
- extname
- file?
- fnmatch
- fnmatch?
- grpowned?
- identical?
- inspect
- install
- link
- link_force
- ln
- ln_f
- ln_s
- ln_sf
- mtime
- mv
- new
- owned?
- pipe?
- readable?
- readable_real?
- relative
- rename
- restat
- rm
- rm_f
- setgid?
- setuid?
- size
- size?
- socket?
- split
- stat
- stat!
- sticky?
- symlink
- symlink_force
- to_s
- touch
- unlink
- unlink_force
- utime
- writable?
- writable_real?
- zero?
Separator | = | ::File::Separator |
[R] | path | |
[R] | relpath |
Factory method.
[ show source ]
# 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
[ show source ]
# File lib/folio/fileobject.rb, line 40 def initialize(path) raise FileNotFound unless ::File.exist?(path) @relpath = path @path = ::File.expand_path(path) end
[ show source ]
# File lib/folio/fileobject.rb, line 225 def <=>(other) path <=> other.to_s end
[ show source ]
# File lib/folio/fileobject.rb, line 229 def ==(other) path == other.path end
[ show source ]
# File lib/folio/fileobject.rb, line 159 def atime ; stat.atime ; end
[ show source ]
# File lib/folio/fileobject.rb, line 180 def basename ; ::File.basename(path) ; end
[ show source ]
# File lib/folio/fileobject.rb, line 154 def blockdev? ; stat.blockdev? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 155 def chardev? ; stat.chardev? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 105 def chmod(mode) ::File.chmod(mode, path) end
[ show source ]
# File lib/folio/fileobject.rb, line 109 def chown(user, group) ::File.chown(user, group, path) end
Copy file to destination path.
[ show source ]
# File lib/folio/fileobject.rb, line 124 def cp(dest) util.cp(path, dest) end
[ show source ]
# File lib/folio/fileobject.rb, line 160 def ctime ; stat.ctime ; end
Alias for unlink
Alias for unlink_force
[ show source ]
# File lib/folio/fileobject.rb, line 153 def directory? ; stat.directory? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 181 def dirname ; ::File.dirname(path) ; end
[ show source ]
# File lib/folio/fileobject.rb, line 53 def exist? ::FileTest.exist?(path) end
[ show source ]
# File lib/folio/fileobject.rb, line 182 def extname ; ::File.extname(path) ; end
[ show source ]
# File lib/folio/fileobject.rb, line 152 def file? ; stat.file? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 209 def fnmatch(pattern, flags=0) ::File.fnmatch(path, pattern, flags) end
Alias for fnmatch
[ show source ]
# File lib/folio/fileobject.rb, line 161 def grpowned? ; stat.grpowned? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 162 def identical? ; stat.identical? ; end
Inspect returns the path string relative to the current working directory.
[ show source ]
# File lib/folio/fileobject.rb, line 220 def inspect; "#{relative}"; end
Install file to destination path.
[ show source ]
# File lib/folio/fileobject.rb, line 129 def install(dest, mode=nil) util.install(path, dest, mode) end
[ show source ]
# File lib/folio/fileobject.rb, line 62 def link(new) ::File.ln(path, new) end
[ show source ]
# File lib/folio/fileobject.rb, line 67 def link_force(new) ::File.remove(new) link(new) end
Alias for link
Alias for link_force
Alias for symlink
Alias for symlink_force
[ show source ]
# File lib/folio/fileobject.rb, line 163 def mtime ; stat.mtime ; end
Alias for rename
[ show source ]
# File lib/folio/fileobject.rb, line 164 def owned? ; stat.owned? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 157 def pipe? ; stat.pipe? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 165 def readable? ; stat.readable? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 166 def readable_real? ; stat.readable_real ; end
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.
[ show source ]
# 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
[ show source ]
# File lib/folio/fileobject.rb, line 84 def rename(dest) ::File.rename(path, dest) @relpath = dest @path = ::File.expand_path(dest) end
Refresh status cache.
[ show source ]
# File lib/folio/fileobject.rb, line 147 def restat @stat = File.stat(path) end
Alias for unlink
Alias for unlink_force
[ show source ]
# File lib/folio/fileobject.rb, line 167 def setgid? ; stat.setgid? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 168 def setuid? ; stat.setuid? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 169 def size ; stat.size ; end
[ show source ]
# File lib/folio/fileobject.rb, line 170 def size? ; stat.size? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 156 def socket? ; stat.socket? ; end
TODO: I don‘t like the name of this.
[ show source ]
# File lib/folio/fileobject.rb, line 185 def split ; ::File.split(path) ; end
Get stat and cache it.
[ show source ]
# File lib/folio/fileobject.rb, line 142 def stat @stat ||= File.stat(path) end
Alias for restat
[ show source ]
# File lib/folio/fileobject.rb, line 171 def sticky? ; stat.sticky? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 73 def symlink(new) ::File.symlink(path, new) end
[ show source ]
# File lib/folio/fileobject.rb, line 78 def symlink_force(new) ::File.remove(new) symlink(new) end
Returns the path string.
[ show source ]
# File lib/folio/fileobject.rb, line 223 def to_s ; path ; end
[ show source ]
# File lib/folio/fileobject.rb, line 133 def touch util.touch(path) end
how to handle —b/c it disappears?
[ show source ]
# File lib/folio/fileobject.rb, line 92 def unlink ::File.delete(path) end
[ show source ]
# File lib/folio/fileobject.rb, line 98 def unlink_force ::File.remove(new) unlink(path) end
[ show source ]
# File lib/folio/fileobject.rb, line 113 def utime(atime, mtime) ::File.utime(atime, mtime, path) end
[ show source ]
# File lib/folio/fileobject.rb, line 172 def writable? ; stat.writable? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 173 def writable_real? ; stat.writable_real? ; end
[ show source ]
# File lib/folio/fileobject.rb, line 174 def zero? ; stat.zero? ; end