class Aruba::Platforms::UnixPlatform
WARNING: All methods found here are not considered part of the public API of aruba.
Those methods can be changed at any time in the feature or removed without any further notice.
This includes all methods for the UNIX platform
@private
Public Class Methods
# File lib/aruba/platforms/unix_platform.rb, line 32 def self.match? !FFI::Platform.windows? end
Public Instance Methods
Is absolute path
# File lib/aruba/platforms/unix_platform.rb, line 182 def absolute_path?(path) Pathname.new(path).absolute? end
# File lib/aruba/platforms/unix_platform.rb, line 44 def announcer Announcer end
Change to directory
# File lib/aruba/platforms/unix_platform.rb, line 128 def chdir(dir_name, &block) dir_name = ::File.expand_path(dir_name.to_s) with_environment 'OLDPWD' => getwd, 'PWD' => dir_name do ::Dir.chdir(dir_name, &block) end end
Change mode of file/directory
# File lib/aruba/platforms/unix_platform.rb, line 152 def chmod(mode, args, options) FileUtils.chmod_R(mode, args, options) end
Check if command is relative
@return [TrueClass, FalseClass]
true * command.sh false * /bin/command.sh * bin/command.sh
# File lib/aruba/platforms/unix_platform.rb, line 214 def command?(path) p = Pathname.new(path) p.relative? && p.basename == p end
# File lib/aruba/platforms/unix_platform.rb, line 48 def command_monitor CommandMonitor end
# File lib/aruba/platforms/unix_platform.rb, line 40 def command_string UnixCommandString end
Copy file/directory
# File lib/aruba/platforms/unix_platform.rb, line 142 def cp(args, options) FileUtils.cp_r(args, options) end
# File lib/aruba/platforms/unix_platform.rb, line 64 def create_file(*args) ArubaFileCreator.new.call(*args) end
# File lib/aruba/platforms/unix_platform.rb, line 68 def create_fixed_size_file(*args) ArubaFixedSizeFileCreator.new.call(*args) end
# File lib/aruba/platforms/unix_platform.rb, line 88 def current_ruby ::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) end
# File lib/aruba/platforms/unix_platform.rb, line 84 def deprecated(msg) warn(format('%s. Called by %s', msg, caller[1])) end
# File lib/aruba/platforms/unix_platform.rb, line 76 def detect_ruby(cmd) if cmd =~ /^ruby\s/ cmd.gsub(/^ruby\s/, "#{current_ruby} ") else cmd end end
# File lib/aruba/platforms/unix_platform.rb, line 60 def determine_disk_usage(*args) DetermineDiskUsage.new.call(*args) end
# File lib/aruba/platforms/unix_platform.rb, line 56 def determine_file_size(*args) DetermineFileSize.new.call(*args) end
Exists and is directory
# File lib/aruba/platforms/unix_platform.rb, line 162 def directory?(f) File.directory? f end
@deprecated Add newline at the end
# File lib/aruba/platforms/unix_platform.rb, line 94 def ensure_newline(str) deprecated('The use of "#ensure_newline" is deprecated. It will be removed soon') str.chomp << "\n" end
# File lib/aruba/platforms/unix_platform.rb, line 36 def environment_variables UnixEnvironmentVariables.new end
Path is executable
# File lib/aruba/platforms/unix_platform.rb, line 172 def executable?(f) File.executable?(f) end
Path Exists
# File lib/aruba/platforms/unix_platform.rb, line 167 def exist?(f) File.exist? f end
Expand path
# File lib/aruba/platforms/unix_platform.rb, line 177 def expand_path(path, base) File.expand_path(path, base) end
Exists and is file
# File lib/aruba/platforms/unix_platform.rb, line 157 def file?(f) File.file? f end
Get current working directory
# File lib/aruba/platforms/unix_platform.rb, line 123 def getwd Dir.getwd end
# File lib/aruba/platforms/unix_platform.rb, line 52 def logger ArubaLogger end
Create directory and subdirectories
# File lib/aruba/platforms/unix_platform.rb, line 109 def mkdir(dir_name) dir_name = ::File.expand_path(dir_name) ::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name) end
Move file/directory
# File lib/aruba/platforms/unix_platform.rb, line 147 def mv(args, options) FileUtils.mv(args, options) end
Check if command is relative
@return [TrueClass, FalseClass]
true * bin/command.sh false * /bin/command.sh * command.sh
# File lib/aruba/platforms/unix_platform.rb, line 200 def relative_command?(path) p = ArubaPath.new(path) p.relative? && p.depth > 1 end
Is relative path
# File lib/aruba/platforms/unix_platform.rb, line 187 def relative_path?(path) Pathname.new(path).relative? end
# File lib/aruba/platforms/unix_platform.rb, line 100 def require_matching_files(pattern, base) if RUBY_VERSION < '1.9.3' ::Dir.glob(::File.expand_path(pattern, base)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) } else ::Dir.glob(::File.expand_path(pattern, base)).each { |f| require_relative f } end end
Remove file, directory + sub-directories
# File lib/aruba/platforms/unix_platform.rb, line 116 def rm(paths, options = {}) paths = Array(paths).map { |p| ::File.expand_path(p) } FileUtils.rm_r(paths, options) end
Transform hash to a string table which can be output on stderr/stdout
# File lib/aruba/platforms/unix_platform.rb, line 248 def simple_table(hash) SimpleTable.new(hash).to_s end
Touch file, directory
# File lib/aruba/platforms/unix_platform.rb, line 137 def touch(args, options) FileUtils.touch(args, options) end
Unescape string
@param [String] string
The string which should be unescaped, e.g. the output of a command
@return
The string stripped from escape sequences
# File lib/aruba/platforms/unix_platform.rb, line 237 def unescape(string, keep_ansi = true) # rubocop:disable Metrics/LineLength deprecated('The use of "Aruba.platform.unescape" is deprecated. Please use "#unescape_text" and "#sanitize_text" instead. But be aware it uses a different implementation') # rubocop:enable Metrics/LineLength string = string.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e") string = string.gsub(/\e\[\d+(?>(;\d+)*)m/, '') unless keep_ansi string end
Resolve path for command using the PATH-environment variable
Mostly taken from here: github.com/djberg96/ptools
@param [#to_s] program
The name of the program which should be resolved
@param [String] path
The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a UNIX-system
# File lib/aruba/platforms/unix_platform.rb, line 262 def which(program, path = ENV['PATH']) UnixWhich.new.call(program, path) end
# File lib/aruba/platforms/unix_platform.rb, line 72 def with_environment(env = {}, &block) LocalEnvironment.new.call(env, &block) end
Write to file
# File lib/aruba/platforms/unix_platform.rb, line 220 def write_file(path, content) if RUBY_VERSION < '1.9.3' File.open(path, 'wb') do |f| f.print content end else File.write(path, content) end end