Class: Aruba::Platforms::UnixPlatform
- Inherits:
-
Object
- Object
- Aruba::Platforms::UnixPlatform
- Defined in:
- lib/aruba/platforms/unix_platform.rb
Overview
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
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#absolute_path?(path) ⇒ Boolean
Is absolute path.
- #announcer ⇒ Object
- #builtin_shell_commands ⇒ Object
-
#chdir(dir_name, &block) ⇒ Object
Change to directory.
-
#chmod(mode, args, options) ⇒ Object
Change mode of file/directory.
-
#command?(path) ⇒ Boolean
Check if command is relative.
- #command_monitor ⇒ Object
- #command_string ⇒ Object
-
#cp(src, dest) ⇒ Object
Copy file/directory.
- #create_file(*args) ⇒ Object
- #create_fixed_size_file(*args) ⇒ Object
- #current_ruby ⇒ Object
- #default_shell ⇒ Object
- #deprecated(msg) ⇒ Object
- #detect_ruby(cmd) ⇒ Object
- #determine_disk_usage(paths) ⇒ Object
- #determine_file_size(*args) ⇒ Object
-
#directory?(f) ⇒ Boolean
Exists and is directory.
- #environment_variables ⇒ Object
-
#executable?(f) ⇒ Boolean
Path is executable.
-
#exist?(f) ⇒ Boolean
Path Exists.
-
#expand_path(path, base) ⇒ Object
Expand path.
-
#file?(f) ⇒ Boolean
Exists and is file.
- #filesystem_status ⇒ Object
-
#getwd ⇒ Object
Get current working directory.
- #logger ⇒ Object
-
#mkdir(dir_name) ⇒ Object
Create directory and subdirectories.
-
#mv(src, dest) ⇒ Object
Move file/directory.
-
#relative_command?(path) ⇒ Boolean
Check if command is relative.
-
#relative_path?(path) ⇒ Boolean
Is relative path.
- #require_matching_files(pattern, base) ⇒ Object
-
#rm(paths, options = {}) ⇒ Object
Remove file, directory + sub-directories.
-
#simple_table(hash, opts = {}) ⇒ Object
Transform hash to a string table which can be output on stderr/stdout.
- #term_signal_supported? ⇒ Boolean
-
#touch(args, options) ⇒ Object
Touch file, directory.
-
#which(program, path = ENV["PATH"]) ⇒ Object
Resolve path for command using the PATH-environment variable.
- #with_environment(env = {}, &block) ⇒ Object
-
#write_file(path, content) ⇒ Object
Write to file.
Class Method Details
.match? ⇒ Boolean
34 35 36 |
# File 'lib/aruba/platforms/unix_platform.rb', line 34 def self.match? !Gem.win_platform? end |
Instance Method Details
#absolute_path?(path) ⇒ Boolean
Is absolute path
180 181 182 |
# File 'lib/aruba/platforms/unix_platform.rb', line 180 def absolute_path?(path) Pathname.new(path).absolute? end |
#announcer ⇒ Object
50 51 52 |
# File 'lib/aruba/platforms/unix_platform.rb', line 50 def announcer Announcer end |
#builtin_shell_commands ⇒ Object
241 242 243 |
# File 'lib/aruba/platforms/unix_platform.rb', line 241 def builtin_shell_commands [] end |
#chdir(dir_name, &block) ⇒ Object
Change to directory
126 127 128 129 130 131 132 |
# File 'lib/aruba/platforms/unix_platform.rb', line 126 def chdir(dir_name, &block) dir_name = ::File.(dir_name.to_s) with_environment "OLDPWD" => getwd, "PWD" => dir_name do ::Dir.chdir(dir_name, &block) end end |
#chmod(mode, args, options) ⇒ Object
Change mode of file/directory
150 151 152 |
# File 'lib/aruba/platforms/unix_platform.rb', line 150 def chmod(mode, args, ) FileUtils.chmod_R(mode, args, **) end |
#command?(path) ⇒ Boolean
Check if command is relative
212 213 214 215 |
# File 'lib/aruba/platforms/unix_platform.rb', line 212 def command?(path) p = Pathname.new(path) p.relative? && p.basename == p end |
#command_monitor ⇒ Object
54 55 56 |
# File 'lib/aruba/platforms/unix_platform.rb', line 54 def command_monitor CommandMonitor end |
#command_string ⇒ Object
42 43 44 |
# File 'lib/aruba/platforms/unix_platform.rb', line 42 def command_string UnixCommandString end |
#cp(src, dest) ⇒ Object
Copy file/directory
140 141 142 |
# File 'lib/aruba/platforms/unix_platform.rb', line 140 def cp(src, dest) FileUtils.cp_r(src, dest) end |
#create_file(*args) ⇒ Object
70 71 72 |
# File 'lib/aruba/platforms/unix_platform.rb', line 70 def create_file(*args) ArubaFileCreator.new.call(*args) end |
#create_fixed_size_file(*args) ⇒ Object
74 75 76 |
# File 'lib/aruba/platforms/unix_platform.rb', line 74 def create_fixed_size_file(*args) ArubaFixedSizeFileCreator.new.call(*args) end |
#current_ruby ⇒ Object
98 99 100 |
# File 'lib/aruba/platforms/unix_platform.rb', line 98 def current_ruby ::File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"]) end |
#default_shell ⇒ Object
82 83 84 |
# File 'lib/aruba/platforms/unix_platform.rb', line 82 def default_shell "bash" end |
#deprecated(msg) ⇒ Object
94 95 96 |
# File 'lib/aruba/platforms/unix_platform.rb', line 94 def deprecated(msg) warn(format("%s. Called by %s", msg, caller[1])) end |
#detect_ruby(cmd) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/aruba/platforms/unix_platform.rb', line 86 def detect_ruby(cmd) if /^ruby\s/.match?(cmd) cmd.gsub(/^ruby\s/, "#{current_ruby} ") else cmd end end |
#determine_disk_usage(paths) ⇒ Object
66 67 68 |
# File 'lib/aruba/platforms/unix_platform.rb', line 66 def determine_disk_usage(paths) DetermineDiskUsage.new.call(paths) end |
#determine_file_size(*args) ⇒ Object
62 63 64 |
# File 'lib/aruba/platforms/unix_platform.rb', line 62 def determine_file_size(*args) DetermineFileSize.new.call(*args) end |
#directory?(f) ⇒ Boolean
Exists and is directory
160 161 162 |
# File 'lib/aruba/platforms/unix_platform.rb', line 160 def directory?(f) File.directory? f end |
#environment_variables ⇒ Object
38 39 40 |
# File 'lib/aruba/platforms/unix_platform.rb', line 38 def environment_variables UnixEnvironmentVariables end |
#executable?(f) ⇒ Boolean
Path is executable
170 171 172 |
# File 'lib/aruba/platforms/unix_platform.rb', line 170 def executable?(f) File.executable?(f) end |
#exist?(f) ⇒ Boolean
Path Exists
165 166 167 |
# File 'lib/aruba/platforms/unix_platform.rb', line 165 def exist?(f) File.exist? f end |
#expand_path(path, base) ⇒ Object
Expand path
175 176 177 |
# File 'lib/aruba/platforms/unix_platform.rb', line 175 def (path, base) File.(path, base) end |
#file?(f) ⇒ Boolean
Exists and is file
155 156 157 |
# File 'lib/aruba/platforms/unix_platform.rb', line 155 def file?(f) File.file? f end |
#filesystem_status ⇒ Object
46 47 48 |
# File 'lib/aruba/platforms/unix_platform.rb', line 46 def filesystem_status FilesystemStatus end |
#getwd ⇒ Object
Get current working directory
121 122 123 |
# File 'lib/aruba/platforms/unix_platform.rb', line 121 def getwd Dir.getwd end |
#logger ⇒ Object
58 59 60 |
# File 'lib/aruba/platforms/unix_platform.rb', line 58 def logger ArubaLogger end |
#mkdir(dir_name) ⇒ Object
Create directory and subdirectories
107 108 109 110 111 |
# File 'lib/aruba/platforms/unix_platform.rb', line 107 def mkdir(dir_name) dir_name = ::File.(dir_name) ::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name) end |
#mv(src, dest) ⇒ Object
Move file/directory
145 146 147 |
# File 'lib/aruba/platforms/unix_platform.rb', line 145 def mv(src, dest) FileUtils.mv(src, dest) end |
#relative_command?(path) ⇒ Boolean
Check if command is relative
198 199 200 201 |
# File 'lib/aruba/platforms/unix_platform.rb', line 198 def relative_command?(path) p = Pathname.new(path) p.relative? && p.basename != p end |
#relative_path?(path) ⇒ Boolean
Is relative path
185 186 187 |
# File 'lib/aruba/platforms/unix_platform.rb', line 185 def relative_path?(path) Pathname.new(path).relative? end |
#require_matching_files(pattern, base) ⇒ Object
102 103 104 |
# File 'lib/aruba/platforms/unix_platform.rb', line 102 def require_matching_files(pattern, base) ::Dir.glob(::File.(pattern, base)).sort.each { |f| require_relative f } end |
#rm(paths, options = {}) ⇒ Object
Remove file, directory + sub-directories
114 115 116 117 118 |
# File 'lib/aruba/platforms/unix_platform.rb', line 114 def rm(paths, = {}) paths = Array(paths).map { |p| ::File.(p) } FileUtils.rm_r(paths, **) end |
#simple_table(hash, opts = {}) ⇒ Object
Transform hash to a string table which can be output on stderr/stdout
223 224 225 |
# File 'lib/aruba/platforms/unix_platform.rb', line 223 def simple_table(hash, opts = {}) SimpleTable.new(hash, opts).to_s end |
#term_signal_supported? ⇒ Boolean
245 246 247 |
# File 'lib/aruba/platforms/unix_platform.rb', line 245 def term_signal_supported? true end |
#touch(args, options) ⇒ Object
Touch file, directory
135 136 137 |
# File 'lib/aruba/platforms/unix_platform.rb', line 135 def touch(args, ) FileUtils.touch(args, **) end |
#which(program, path = ENV["PATH"]) ⇒ Object
Resolve path for command using the PATH-environment variable
Mostly taken from here: github.com/djberg96/ptools
237 238 239 |
# File 'lib/aruba/platforms/unix_platform.rb', line 237 def which(program, path = ENV["PATH"]) UnixWhich.new.call(program, path) end |
#with_environment(env = {}, &block) ⇒ Object
78 79 80 |
# File 'lib/aruba/platforms/unix_platform.rb', line 78 def with_environment(env = {}, &block) LocalEnvironment.new.call(env, &block) end |
#write_file(path, content) ⇒ Object
Write to file
218 219 220 |
# File 'lib/aruba/platforms/unix_platform.rb', line 218 def write_file(path, content) File.write(path, content) end |