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
-
#chdir(dir_name, &block) ⇒ Object
Change to directory.
-
#chmod(mode, args, options) ⇒ Object
Change mode of file/directory.
-
#command?(path) ⇒ TrueClass, FalseClass
Check if command is relative.
-
#command_monitor ⇒ Object
-
#command_string ⇒ Object
-
#cp(args, options) ⇒ 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(*args) ⇒ Object
-
#determine_file_size(*args) ⇒ Object
-
#directory?(f) ⇒ Boolean
Exists and is directory.
-
#ensure_newline(str) ⇒ Object
deprecated
Deprecated.
-
#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(args, options) ⇒ Object
Move file/directory.
-
#relative_command?(path) ⇒ TrueClass, FalseClass
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.
-
#touch(args, options) ⇒ Object
Touch file, directory.
-
#unescape(string, keep_ansi = true) ⇒ Object
Unescape string.
-
#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
33 34 35 |
# File 'lib/aruba/platforms/unix_platform.rb', line 33 def self.match? !FFI::Platform.windows? end |
Instance Method Details
#absolute_path?(path) ⇒ Boolean
Is absolute path
191 192 193 |
# File 'lib/aruba/platforms/unix_platform.rb', line 191 def absolute_path?(path) Pathname.new(path).absolute? end |
#announcer ⇒ Object
49 50 51 |
# File 'lib/aruba/platforms/unix_platform.rb', line 49 def announcer Announcer end |
#chdir(dir_name, &block) ⇒ Object
Change to directory
137 138 139 140 141 142 143 |
# File 'lib/aruba/platforms/unix_platform.rb', line 137 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
161 162 163 |
# File 'lib/aruba/platforms/unix_platform.rb', line 161 def chmod(mode, args, ) FileUtils.chmod_R(mode, args, ) end |
#command?(path) ⇒ TrueClass, FalseClass
Check if command is relative
223 224 225 226 |
# File 'lib/aruba/platforms/unix_platform.rb', line 223 def command?(path) p = Pathname.new(path) p.relative? && p.basename == p end |
#command_monitor ⇒ Object
53 54 55 |
# File 'lib/aruba/platforms/unix_platform.rb', line 53 def command_monitor CommandMonitor end |
#command_string ⇒ Object
41 42 43 |
# File 'lib/aruba/platforms/unix_platform.rb', line 41 def command_string UnixCommandString end |
#cp(args, options) ⇒ Object
Copy file/directory
151 152 153 |
# File 'lib/aruba/platforms/unix_platform.rb', line 151 def cp(args, ) FileUtils.cp_r(args, ) end |
#create_file(*args) ⇒ Object
69 70 71 |
# File 'lib/aruba/platforms/unix_platform.rb', line 69 def create_file(*args) ArubaFileCreator.new.call(*args) end |
#create_fixed_size_file(*args) ⇒ Object
73 74 75 |
# File 'lib/aruba/platforms/unix_platform.rb', line 73 def create_fixed_size_file(*args) ArubaFixedSizeFileCreator.new.call(*args) end |
#current_ruby ⇒ Object
97 98 99 |
# File 'lib/aruba/platforms/unix_platform.rb', line 97 def current_ruby ::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) end |
#default_shell ⇒ Object
81 82 83 |
# File 'lib/aruba/platforms/unix_platform.rb', line 81 def default_shell 'bash' end |
#deprecated(msg) ⇒ Object
93 94 95 |
# File 'lib/aruba/platforms/unix_platform.rb', line 93 def deprecated(msg) warn(format('%s. Called by %s', msg, caller[1])) end |
#detect_ruby(cmd) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/aruba/platforms/unix_platform.rb', line 85 def detect_ruby(cmd) if cmd =~ /^ruby\s/ cmd.gsub(/^ruby\s/, "#{current_ruby} ") else cmd end end |
#determine_disk_usage(*args) ⇒ Object
65 66 67 |
# File 'lib/aruba/platforms/unix_platform.rb', line 65 def determine_disk_usage(*args) DetermineDiskUsage.new.call(*args) end |
#determine_file_size(*args) ⇒ Object
61 62 63 |
# File 'lib/aruba/platforms/unix_platform.rb', line 61 def determine_file_size(*args) DetermineFileSize.new.call(*args) end |
#directory?(f) ⇒ Boolean
Exists and is directory
171 172 173 |
# File 'lib/aruba/platforms/unix_platform.rb', line 171 def directory?(f) File.directory? f end |
#ensure_newline(str) ⇒ Object
Add newline at the end
103 104 105 106 107 |
# File 'lib/aruba/platforms/unix_platform.rb', line 103 def ensure_newline(str) deprecated('The use of "#ensure_newline" is deprecated. It will be removed soon') str.chomp << "\n" end |
#environment_variables ⇒ Object
37 38 39 |
# File 'lib/aruba/platforms/unix_platform.rb', line 37 def environment_variables UnixEnvironmentVariables end |
#executable?(f) ⇒ Boolean
Path is executable
181 182 183 |
# File 'lib/aruba/platforms/unix_platform.rb', line 181 def executable?(f) File.executable?(f) end |
#exist?(f) ⇒ Boolean
Path Exists
176 177 178 |
# File 'lib/aruba/platforms/unix_platform.rb', line 176 def exist?(f) File.exist? f end |
#expand_path(path, base) ⇒ Object
Expand path
186 187 188 |
# File 'lib/aruba/platforms/unix_platform.rb', line 186 def (path, base) File.(path, base) end |
#file?(f) ⇒ Boolean
Exists and is file
166 167 168 |
# File 'lib/aruba/platforms/unix_platform.rb', line 166 def file?(f) File.file? f end |
#filesystem_status ⇒ Object
45 46 47 |
# File 'lib/aruba/platforms/unix_platform.rb', line 45 def filesystem_status FilesystemStatus end |
#getwd ⇒ Object
Get current working directory
132 133 134 |
# File 'lib/aruba/platforms/unix_platform.rb', line 132 def getwd Dir.getwd end |
#logger ⇒ Object
57 58 59 |
# File 'lib/aruba/platforms/unix_platform.rb', line 57 def logger ArubaLogger end |
#mkdir(dir_name) ⇒ Object
Create directory and subdirectories
118 119 120 121 122 |
# File 'lib/aruba/platforms/unix_platform.rb', line 118 def mkdir(dir_name) dir_name = ::File.(dir_name) ::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name) end |
#mv(args, options) ⇒ Object
Move file/directory
156 157 158 |
# File 'lib/aruba/platforms/unix_platform.rb', line 156 def mv(args, ) FileUtils.mv(args, ) end |
#relative_command?(path) ⇒ TrueClass, FalseClass
Check if command is relative
209 210 211 212 |
# File 'lib/aruba/platforms/unix_platform.rb', line 209 def relative_command?(path) p = ArubaPath.new(path) p.relative? && p.depth > 1 end |
#relative_path?(path) ⇒ Boolean
Is relative path
196 197 198 |
# File 'lib/aruba/platforms/unix_platform.rb', line 196 def relative_path?(path) Pathname.new(path).relative? end |
#require_matching_files(pattern, base) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/aruba/platforms/unix_platform.rb', line 109 def require_matching_files(pattern, base) if RUBY_VERSION < '1.9.3' ::Dir.glob(::File.(pattern, base)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) } else ::Dir.glob(::File.(pattern, base)).each { |f| require_relative f } end end |
#rm(paths, options = {}) ⇒ Object
Remove file, directory + sub-directories
125 126 127 128 129 |
# File 'lib/aruba/platforms/unix_platform.rb', line 125 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
257 258 259 |
# File 'lib/aruba/platforms/unix_platform.rb', line 257 def simple_table(hash, opts = {}) SimpleTable.new(hash, opts).to_s end |
#touch(args, options) ⇒ Object
Touch file, directory
146 147 148 |
# File 'lib/aruba/platforms/unix_platform.rb', line 146 def touch(args, ) FileUtils.touch(args, ) end |
#unescape(string, keep_ansi = true) ⇒ Object
Unescape string
246 247 248 249 250 251 252 253 254 |
# File 'lib/aruba/platforms/unix_platform.rb', line 246 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 |
#which(program, path = ENV['PATH']) ⇒ Object
Resolve path for command using the PATH-environment variable
Mostly taken from here: https://github.com/djberg96/ptools
271 272 273 |
# File 'lib/aruba/platforms/unix_platform.rb', line 271 def which(program, path = ENV['PATH']) UnixWhich.new.call(program, path) end |
#with_environment(env = {}, &block) ⇒ Object
77 78 79 |
# File 'lib/aruba/platforms/unix_platform.rb', line 77 def with_environment(env = {}, &block) LocalEnvironment.new.call(env, &block) end |
#write_file(path, content) ⇒ Object
Write to file
229 230 231 232 233 234 235 236 237 |
# File 'lib/aruba/platforms/unix_platform.rb', line 229 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 |