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_replaced_environment(env = {}, &block) ⇒ Object
-
#write_file(path, content) ⇒ Object
Write to file.
Class Method Details
.match? ⇒ Boolean
36 37 38 |
# File 'lib/aruba/platforms/unix_platform.rb', line 36 def self.match? !Gem.win_platform? end |
Instance Method Details
#absolute_path?(path) ⇒ Boolean
Is absolute path
182 183 184 |
# File 'lib/aruba/platforms/unix_platform.rb', line 182 def absolute_path?(path) Pathname.new(path).absolute? end |
#announcer ⇒ Object
52 53 54 |
# File 'lib/aruba/platforms/unix_platform.rb', line 52 def announcer Announcer end |
#builtin_shell_commands ⇒ Object
243 244 245 |
# File 'lib/aruba/platforms/unix_platform.rb', line 243 def builtin_shell_commands [] end |
#chdir(dir_name, &block) ⇒ Object
Change to directory
128 129 130 131 132 133 134 |
# File 'lib/aruba/platforms/unix_platform.rb', line 128 def chdir(dir_name, &block) dir_name = ::File.(dir_name.to_s) with_replaced_environment 'OLDPWD' => getwd, 'PWD' => dir_name do ::Dir.chdir(dir_name, &block) end end |
#chmod(mode, args, options) ⇒ Object
Change mode of file/directory
152 153 154 |
# File 'lib/aruba/platforms/unix_platform.rb', line 152 def chmod(mode, args, ) FileUtils.chmod_R(mode, args, **) end |
#command?(path) ⇒ Boolean
Check if command is relative
214 215 216 217 |
# File 'lib/aruba/platforms/unix_platform.rb', line 214 def command?(path) p = Pathname.new(path) p.relative? && p.basename == p end |
#command_monitor ⇒ Object
56 57 58 |
# File 'lib/aruba/platforms/unix_platform.rb', line 56 def command_monitor CommandMonitor end |
#command_string ⇒ Object
44 45 46 |
# File 'lib/aruba/platforms/unix_platform.rb', line 44 def command_string UnixCommandString end |
#cp(src, dest) ⇒ Object
Copy file/directory
142 143 144 |
# File 'lib/aruba/platforms/unix_platform.rb', line 142 def cp(src, dest) FileUtils.cp_r(src, dest) end |
#create_file(*args) ⇒ Object
72 73 74 |
# File 'lib/aruba/platforms/unix_platform.rb', line 72 def create_file(*args) ArubaFileCreator.new.call(*args) end |
#create_fixed_size_file(*args) ⇒ Object
76 77 78 |
# File 'lib/aruba/platforms/unix_platform.rb', line 76 def create_fixed_size_file(*args) ArubaFixedSizeFileCreator.new.call(*args) end |
#current_ruby ⇒ Object
100 101 102 |
# File 'lib/aruba/platforms/unix_platform.rb', line 100 def current_ruby ::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) end |
#default_shell ⇒ Object
84 85 86 |
# File 'lib/aruba/platforms/unix_platform.rb', line 84 def default_shell 'bash' end |
#deprecated(msg) ⇒ Object
96 97 98 |
# File 'lib/aruba/platforms/unix_platform.rb', line 96 def deprecated(msg) warn(format('%s. Called by %s', msg, caller[1])) end |
#detect_ruby(cmd) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/aruba/platforms/unix_platform.rb', line 88 def detect_ruby(cmd) if /^ruby\s/.match?(cmd) cmd.gsub(/^ruby\s/, "#{current_ruby} ") else cmd end end |
#determine_disk_usage(paths) ⇒ Object
68 69 70 |
# File 'lib/aruba/platforms/unix_platform.rb', line 68 def determine_disk_usage(paths) DetermineDiskUsage.new.call(paths) end |
#determine_file_size(*args) ⇒ Object
64 65 66 |
# File 'lib/aruba/platforms/unix_platform.rb', line 64 def determine_file_size(*args) DetermineFileSize.new.call(*args) end |
#directory?(f) ⇒ Boolean
Exists and is directory
162 163 164 |
# File 'lib/aruba/platforms/unix_platform.rb', line 162 def directory?(f) File.directory? f end |
#environment_variables ⇒ Object
40 41 42 |
# File 'lib/aruba/platforms/unix_platform.rb', line 40 def environment_variables UnixEnvironmentVariables end |
#executable?(f) ⇒ Boolean
Path is executable
172 173 174 |
# File 'lib/aruba/platforms/unix_platform.rb', line 172 def executable?(f) File.executable?(f) end |
#exist?(f) ⇒ Boolean
Path Exists
167 168 169 |
# File 'lib/aruba/platforms/unix_platform.rb', line 167 def exist?(f) File.exist? f end |
#expand_path(path, base) ⇒ Object
Expand path
177 178 179 |
# File 'lib/aruba/platforms/unix_platform.rb', line 177 def (path, base) File.(path, base) end |
#file?(f) ⇒ Boolean
Exists and is file
157 158 159 |
# File 'lib/aruba/platforms/unix_platform.rb', line 157 def file?(f) File.file? f end |
#filesystem_status ⇒ Object
48 49 50 |
# File 'lib/aruba/platforms/unix_platform.rb', line 48 def filesystem_status FilesystemStatus end |
#getwd ⇒ Object
Get current working directory
123 124 125 |
# File 'lib/aruba/platforms/unix_platform.rb', line 123 def getwd Dir.getwd end |
#logger ⇒ Object
60 61 62 |
# File 'lib/aruba/platforms/unix_platform.rb', line 60 def logger ArubaLogger end |
#mkdir(dir_name) ⇒ Object
Create directory and subdirectories
109 110 111 112 113 |
# File 'lib/aruba/platforms/unix_platform.rb', line 109 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
147 148 149 |
# File 'lib/aruba/platforms/unix_platform.rb', line 147 def mv(src, dest) FileUtils.mv(src, dest) end |
#relative_command?(path) ⇒ Boolean
Check if command is relative
200 201 202 203 |
# File 'lib/aruba/platforms/unix_platform.rb', line 200 def relative_command?(path) p = Pathname.new(path) p.relative? && p.basename != p end |
#relative_path?(path) ⇒ Boolean
Is relative path
187 188 189 |
# File 'lib/aruba/platforms/unix_platform.rb', line 187 def relative_path?(path) Pathname.new(path).relative? end |
#require_matching_files(pattern, base) ⇒ Object
104 105 106 |
# File 'lib/aruba/platforms/unix_platform.rb', line 104 def require_matching_files(pattern, base) ::Dir.glob(::File.(pattern, base)).each { |f| require_relative f } end |
#rm(paths, options = {}) ⇒ Object
Remove file, directory + sub-directories
116 117 118 119 120 |
# File 'lib/aruba/platforms/unix_platform.rb', line 116 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
225 226 227 |
# File 'lib/aruba/platforms/unix_platform.rb', line 225 def simple_table(hash, opts = {}) SimpleTable.new(hash, opts).to_s end |
#term_signal_supported? ⇒ Boolean
247 248 249 |
# File 'lib/aruba/platforms/unix_platform.rb', line 247 def term_signal_supported? true end |
#touch(args, options) ⇒ Object
Touch file, directory
137 138 139 |
# File 'lib/aruba/platforms/unix_platform.rb', line 137 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
239 240 241 |
# File 'lib/aruba/platforms/unix_platform.rb', line 239 def which(program, path = ENV['PATH']) UnixWhich.new.call(program, path) end |
#with_replaced_environment(env = {}, &block) ⇒ Object
80 81 82 |
# File 'lib/aruba/platforms/unix_platform.rb', line 80 def with_replaced_environment(env = {}, &block) LocalEnvironment.new(self).call(env, &block) end |
#write_file(path, content) ⇒ Object
Write to file
220 221 222 |
# File 'lib/aruba/platforms/unix_platform.rb', line 220 def write_file(path, content) File.write(path, content) end |