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.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Class Method Summary collapse
- .dir_entry(dir, child, link_info: true) ⇒ Object
- .info(path, link_info: true, show_filepath: false) ⇒ Object
Instance Method Summary collapse
- #dead? ⇒ Boolean
- #group ⇒ Object
- #hidden? ⇒ Boolean
-
#initialize(name:, parent:, path: nil, link_info: true, show_filepath: false) ⇒ FileInfo
constructor
A new instance of FileInfo.
-
#link_target ⇒ Object
target of a symlink (only available for symlinks).
- #owner ⇒ Object
- #show ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name:, parent:, path: nil, link_info: true, show_filepath: false) ⇒ FileInfo
Returns a new instance of FileInfo.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/colorls/fileinfo.rb', line 14 def initialize(name:, parent:, path: nil, link_info: true, show_filepath: false) @name = name @parent = parent @path = path.nil? ? File.join(parent, name) : +path @stats = File.lstat(@path) @path.force_encoding(ColorLS.file_encoding) handle_symlink(@path) if link_info && @stats.symlink? set_show_name(use_path: show_filepath) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/colorls/fileinfo.rb', line 12 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
12 13 14 |
# File 'lib/colorls/fileinfo.rb', line 12 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/colorls/fileinfo.rb', line 12 def path @path 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
.dir_entry(dir, child, link_info: true) ⇒ Object
31 32 33 |
# File 'lib/colorls/fileinfo.rb', line 31 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, show_filepath: false) ⇒ Object
26 27 28 29 |
# File 'lib/colorls/fileinfo.rb', line 26 def self.info(path, link_info: true, show_filepath: false) FileInfo.new(name: File.basename(path), parent: File.dirname(path), path: path, link_info: link_info, show_filepath: show_filepath) end |
Instance Method Details
#dead? ⇒ Boolean
39 40 41 |
# File 'lib/colorls/fileinfo.rb', line 39 def dead? @dead end |
#group ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/colorls/fileinfo.rb', line 56 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 |
#hidden? ⇒ Boolean
43 44 45 |
# File 'lib/colorls/fileinfo.rb', line 43 def hidden? @name.start_with?('.') end |
#link_target ⇒ Object
target of a symlink (only available for symlinks)
66 67 68 |
# File 'lib/colorls/fileinfo.rb', line 66 def link_target @target end |
#owner ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/colorls/fileinfo.rb', line 47 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 ⇒ Object
35 36 37 |
# File 'lib/colorls/fileinfo.rb', line 35 def show @show_name end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/colorls/fileinfo.rb', line 70 def to_s name end |