Class: ColorLS::FileInfo
- Inherits:
-
Object
- Object
- ColorLS::FileInfo
- 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
- #directory? ⇒ 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).
- #mtime ⇒ Object
- #owned? ⇒ Boolean
- #owner ⇒ Object
- #size ⇒ Object
- #symlink? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(path, link_info = true) ⇒ FileInfo
9 10 11 12 13 14 15 16 |
# File 'lib/colorls/fileinfo.rb', line 9 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.
7 8 9 |
# File 'lib/colorls/fileinfo.rb', line 7 def name @name end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
6 7 8 |
# File 'lib/colorls/fileinfo.rb', line 6 def stats @stats end |
Class Method Details
.info(path) ⇒ Object
18 19 20 |
# File 'lib/colorls/fileinfo.rb', line 18 def self.info(path) FileInfo.new(path) end |
Instance Method Details
#dead? ⇒ Boolean
22 23 24 |
# File 'lib/colorls/fileinfo.rb', line 22 def dead? @dead end |
#directory? ⇒ Boolean
52 53 54 |
# File 'lib/colorls/fileinfo.rb', line 52 def directory? @stats.directory? end |
#group ⇒ Object
37 38 39 40 41 42 |
# File 'lib/colorls/fileinfo.rb', line 37 def group return @@groups[@stats.gid] if @@groups.key? @stats.gid @@groups[@stats.gid] = Etc.getgrgid(@stats.gid).name rescue ArgumentError @stats.gid.to_s end |
#link_target ⇒ Object
target of a symlink (only available for symlinks)
61 62 63 |
# File 'lib/colorls/fileinfo.rb', line 61 def link_target @target end |
#mtime ⇒ Object
44 45 46 |
# File 'lib/colorls/fileinfo.rb', line 44 def mtime @stats.mtime end |
#owned? ⇒ Boolean
33 34 35 |
# File 'lib/colorls/fileinfo.rb', line 33 def owned? @stats.owned? end |
#owner ⇒ Object
26 27 28 29 30 31 |
# File 'lib/colorls/fileinfo.rb', line 26 def owner return @@users[@stats.uid] if @@users.key? @stats.uid @@users[@stats.uid] = Etc.getpwuid(@stats.uid).name rescue ArgumentError @stats.uid.to_s end |
#size ⇒ Object
48 49 50 |
# File 'lib/colorls/fileinfo.rb', line 48 def size @stats.size end |
#symlink? ⇒ Boolean
56 57 58 |
# File 'lib/colorls/fileinfo.rb', line 56 def symlink? @stats.symlink? end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/colorls/fileinfo.rb', line 65 def to_s name end |