Class: ColorLS::FileInfo
- Inherits:
-
Object
- Object
- ColorLS::FileInfo
- Extended by:
- Forwardable
- Defined in:
- lib/colorls/fileinfo.rb
Constant Summary collapse
- @@users =
rubocop:disable Style/ClassVars
{}
- @@groups =
rubocop:disable Style/ClassVars
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Class Method Summary collapse
Instance Method Summary collapse
- #dead? ⇒ Boolean
- #group ⇒ Object
-
#initialize(path, link_info = true) ⇒ FileInfo
constructor
A new instance of FileInfo.
-
#link_target ⇒ Object
target of a symlink (only available for symlinks).
- #owner ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path, link_info = true) ⇒ FileInfo
Returns a new instance of FileInfo.
15 16 17 18 19 20 21 22 23 |
# File 'lib/colorls/fileinfo.rb', line 15 def initialize(path, link_info=true) @name = File.basename(path) @stats = File.lstat(path) return unless link_info && @stats.symlink? @dead = !File.exist?(path) @target = File.readlink(path) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/colorls/fileinfo.rb', line 13 def name @name end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
12 13 14 |
# File 'lib/colorls/fileinfo.rb', line 12 def stats @stats end |
Class Method Details
Instance Method Details
#dead? ⇒ Boolean
29 30 31 |
# File 'lib/colorls/fileinfo.rb', line 29 def dead? @dead end |
#group ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/colorls/fileinfo.rb', line 42 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 ⇒ Object
target of a symlink (only available for symlinks)
52 53 54 |
# File 'lib/colorls/fileinfo.rb', line 52 def link_target @target end |
#owner ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/colorls/fileinfo.rb', line 33 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 |
#to_s ⇒ Object
56 57 58 |
# File 'lib/colorls/fileinfo.rb', line 56 def to_s name end |