class ColorLS::FileInfo
Attributes
name[R]
parent[R]
path[R]
stats[R]
Public Class Methods
dir_entry(dir, child, link_info: true)
click to toggle source
# File lib/colorls/fileinfo.rb, line 28 def self.dir_entry(dir, child, link_info: true) FileInfo.new(name: child, parent: dir, link_info: link_info) end
info(path, link_info: true)
click to toggle source
# File lib/colorls/fileinfo.rb, line 24 def self.info(path, link_info: true) FileInfo.new(name: File.basename(path), parent: File.dirname(path), path: path, link_info: link_info) end
new(name:, parent:, path: nil, link_info: true)
click to toggle source
# File lib/colorls/fileinfo.rb, line 14 def initialize(name:, parent:, path: nil, link_info: true) @name = name @parent = parent @path = path.nil? ? File.join(parent, name) : path @stats = File.lstat(@path) @show_name = nil handle_symlink(@path) if link_info && @stats.symlink? end
Public Instance Methods
dead?()
click to toggle source
# File lib/colorls/fileinfo.rb, line 39 def dead? @dead end
group()
click to toggle source
# File lib/colorls/fileinfo.rb, line 52 def group return @@groups[@stats.gid] if @@groups.key? @stats.gid group = Etc.getgrgid(@stats.gid) @@groups[@stats.gid] = group.nil? ? @stats.gid.to_s : group.name rescue ArgumentError @stats.gid.to_s end
link_target()
click to toggle source
target of a symlink (only available for symlinks)
# File lib/colorls/fileinfo.rb, line 62 def link_target @target end
owner()
click to toggle source
# File lib/colorls/fileinfo.rb, line 43 def owner return @@users[@stats.uid] if @@users.key? @stats.uid user = Etc.getpwuid(@stats.uid) @@users[@stats.uid] = user.nil? ? @stats.uid.to_s : user.name rescue ArgumentError @stats.uid.to_s end
show()
click to toggle source
# File lib/colorls/fileinfo.rb, line 32 def show return @show_name unless @show_name.nil? @show_name = @name.encode(Encoding.find('filesystem'), Encoding.default_external, invalid: :replace, undef: :replace) end
to_s()
click to toggle source
# File lib/colorls/fileinfo.rb, line 66 def to_s name end
Private Instance Methods
handle_symlink(path)
click to toggle source
# File lib/colorls/fileinfo.rb, line 75 def handle_symlink(path) @target = File.readlink(path) @dead = !File.exist?(path) rescue SystemCallError => e $stderr.puts "cannot read symbolic link: #{e}" end