Module: Wright::Util::File Private
- Defined in:
- lib/wright/util/file.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Various file methods.
Class Method Summary collapse
-
.expand_tilde_path(path) ⇒ String
private
Expands tilde symbols in file paths.
-
.file_group(path) ⇒ Integer
private
Returns a file’s owner.
-
.file_mode(path) ⇒ Integer
private
Returns a file’s current mode.
-
.file_owner(path) ⇒ Integer
private
Returns a file’s owner.
-
.ln_sfn(target, link_name) ⇒ void
private
Creates symlinks without descending into directories.
-
.numeric_mode_to_i(mode) ⇒ Integer
private
Converts a numeric mode string to an integer mode.
-
.symbolic_mode_to_i(mode, base_mode, filetype = :file) ⇒ Integer
private
Converts a symbolic mode string to an integer mode value.
Class Method Details
.expand_tilde_path(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Expands tilde symbols in file paths. Path elements other than the first one are left alone.
228 229 230 231 232 233 |
# File 'lib/wright/util/file.rb', line 228 def self.(path) return path unless path.start_with?('~') first, *rest = path.split(::File::SEPARATOR) ::File.join(::File.(first), rest) end |
.file_group(path) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a file’s owner.
208 209 210 |
# File 'lib/wright/util/file.rb', line 208 def self.file_group(path) ::File.exist?(path) ? ::File.stat(path).gid : nil end |
.file_mode(path) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a file’s current mode.
170 171 172 |
# File 'lib/wright/util/file.rb', line 170 def self.file_mode(path) ::File.exist?(path) ? (::File.stat(path).mode & 07777) : nil end |
.file_owner(path) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a file’s owner.
189 190 191 |
# File 'lib/wright/util/file.rb', line 189 def self.file_owner(path) ::File.exist?(path) ? ::File.stat(path).uid : nil end |
.ln_sfn(target, link_name) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Creates symlinks without descending into directories.
If the file denoted by link_name is a symlink to a directory, ln_sfn does not descend into it. Behaves similar to GNU ln(1) or OpenBSD ln(1) when using ln -sfn target link_name.
245 246 247 248 249 250 |
# File 'lib/wright/util/file.rb', line 245 def self.ln_sfn(target, link_name) if ::File.symlink?(link_name) && ::File.directory?(link_name) FileUtils.rm(link_name) end FileUtils.ln_sf(target, link_name) end |
.numeric_mode_to_i(mode) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a numeric mode string to an integer mode.
145 146 147 148 |
# File 'lib/wright/util/file.rb', line 145 def self.numeric_mode_to_i(mode) return mode.to_i unless mode.is_a?(String) mode =~ /\A[0-7]{3,4}\Z/ ? mode.to_i(8) : nil end |
.symbolic_mode_to_i(mode, base_mode, filetype = :file) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a symbolic mode string to an integer mode value.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/wright/util/file.rb', line 76 def self.symbolic_mode_to_i(mode, base_mode, filetype = :file) is_directory = (filetype == :directory) unless symbolic_mode?(mode) fail ArgumentError, "Invalid file mode \"#{mode}\"" end mode_i = base_mode mode.split(/,/).each do |mode_clause| mode_i = mode_clause_to_i(mode_clause, mode_i, is_directory) end mode_i end |