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.
- #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
35 36 37 |
# File 'lib/aruba/platforms/unix_platform.rb', line 35 def self.match? !Gem.win_platform? end |
Instance Method Details
#absolute_path?(path) ⇒ Boolean
Is absolute path
181 182 183 |
# File 'lib/aruba/platforms/unix_platform.rb', line 181 def absolute_path?(path) Pathname.new(path).absolute? end |
#announcer ⇒ Object
51 52 53 |
# File 'lib/aruba/platforms/unix_platform.rb', line 51 def announcer Announcer end |
#builtin_shell_commands ⇒ Object
237 238 239 |
# File 'lib/aruba/platforms/unix_platform.rb', line 237 def builtin_shell_commands [] end |
#chdir(dir_name, &block) ⇒ Object
Change to directory
127 128 129 130 131 132 133 |
# File 'lib/aruba/platforms/unix_platform.rb', line 127 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
151 152 153 |
# File 'lib/aruba/platforms/unix_platform.rb', line 151 def chmod(mode, args, ) FileUtils.chmod_R(mode, args, **) end |
#command?(path) ⇒ Boolean
Check if command is relative
213 214 215 216 |
# File 'lib/aruba/platforms/unix_platform.rb', line 213 def command?(path) p = Pathname.new(path) p.relative? && p.basename == p end |
#command_monitor ⇒ Object
55 56 57 |
# File 'lib/aruba/platforms/unix_platform.rb', line 55 def command_monitor CommandMonitor end |
#command_string ⇒ Object
43 44 45 |
# File 'lib/aruba/platforms/unix_platform.rb', line 43 def command_string UnixCommandString end |
#cp(src, dest) ⇒ Object
Copy file/directory
141 142 143 |
# File 'lib/aruba/platforms/unix_platform.rb', line 141 def cp(src, dest) FileUtils.cp_r(src, dest) end |
#create_file(*args) ⇒ Object
71 72 73 |
# File 'lib/aruba/platforms/unix_platform.rb', line 71 def create_file(*args) ArubaFileCreator.new.call(*args) end |
#create_fixed_size_file(*args) ⇒ Object
75 76 77 |
# File 'lib/aruba/platforms/unix_platform.rb', line 75 def create_fixed_size_file(*args) ArubaFixedSizeFileCreator.new.call(*args) end |
#current_ruby ⇒ Object
99 100 101 |
# File 'lib/aruba/platforms/unix_platform.rb', line 99 def current_ruby ::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) end |
#default_shell ⇒ Object
83 84 85 |
# File 'lib/aruba/platforms/unix_platform.rb', line 83 def default_shell 'bash' end |
#deprecated(msg) ⇒ Object
95 96 97 |
# File 'lib/aruba/platforms/unix_platform.rb', line 95 def deprecated(msg) warn(format('%s. Called by %s', msg, caller[1])) end |
#detect_ruby(cmd) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/aruba/platforms/unix_platform.rb', line 87 def detect_ruby(cmd) if /^ruby\s/.match?(cmd) cmd.gsub(/^ruby\s/, "#{current_ruby} ") else cmd end end |
#determine_disk_usage(paths) ⇒ Object
67 68 69 |
# File 'lib/aruba/platforms/unix_platform.rb', line 67 def determine_disk_usage(paths) DetermineDiskUsage.new.call(paths) end |
#determine_file_size(*args) ⇒ Object
63 64 65 |
# File 'lib/aruba/platforms/unix_platform.rb', line 63 def determine_file_size(*args) DetermineFileSize.new.call(*args) end |
#directory?(f) ⇒ Boolean
Exists and is directory
161 162 163 |
# File 'lib/aruba/platforms/unix_platform.rb', line 161 def directory?(f) File.directory? f end |
#environment_variables ⇒ Object
39 40 41 |
# File 'lib/aruba/platforms/unix_platform.rb', line 39 def environment_variables UnixEnvironmentVariables end |
#executable?(f) ⇒ Boolean
Path is executable
171 172 173 |
# File 'lib/aruba/platforms/unix_platform.rb', line 171 def executable?(f) File.executable?(f) end |
#exist?(f) ⇒ Boolean
Path Exists
166 167 168 |
# File 'lib/aruba/platforms/unix_platform.rb', line 166 def exist?(f) File.exist? f end |
#expand_path(path, base) ⇒ Object
Expand path
176 177 178 |
# File 'lib/aruba/platforms/unix_platform.rb', line 176 def (path, base) File.(path, base) end |
#file?(f) ⇒ Boolean
Exists and is file
156 157 158 |
# File 'lib/aruba/platforms/unix_platform.rb', line 156 def file?(f) File.file? f end |
#filesystem_status ⇒ Object
47 48 49 |
# File 'lib/aruba/platforms/unix_platform.rb', line 47 def filesystem_status FilesystemStatus end |
#getwd ⇒ Object
Get current working directory
122 123 124 |
# File 'lib/aruba/platforms/unix_platform.rb', line 122 def getwd Dir.getwd end |
#logger ⇒ Object
59 60 61 |
# File 'lib/aruba/platforms/unix_platform.rb', line 59 def logger ArubaLogger end |
#mkdir(dir_name) ⇒ Object
Create directory and subdirectories
108 109 110 111 112 |
# File 'lib/aruba/platforms/unix_platform.rb', line 108 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
146 147 148 |
# File 'lib/aruba/platforms/unix_platform.rb', line 146 def mv(src, dest) FileUtils.mv(src, dest) end |
#relative_command?(path) ⇒ Boolean
Check if command is relative
199 200 201 202 |
# File 'lib/aruba/platforms/unix_platform.rb', line 199 def relative_command?(path) p = Pathname.new(path) p.relative? && p.basename != p end |
#relative_path?(path) ⇒ Boolean
Is relative path
186 187 188 |
# File 'lib/aruba/platforms/unix_platform.rb', line 186 def relative_path?(path) Pathname.new(path).relative? end |
#require_matching_files(pattern, base) ⇒ Object
103 104 105 |
# File 'lib/aruba/platforms/unix_platform.rb', line 103 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
115 116 117 118 119 |
# File 'lib/aruba/platforms/unix_platform.rb', line 115 def rm(paths, = {}) paths = Array(paths).map { |p| ::File.(p) } FileUtils.rm_r(paths, **) end |
#term_signal_supported? ⇒ Boolean
241 242 243 |
# File 'lib/aruba/platforms/unix_platform.rb', line 241 def term_signal_supported? true end |
#touch(args, options) ⇒ Object
Touch file, directory
136 137 138 |
# File 'lib/aruba/platforms/unix_platform.rb', line 136 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
233 234 235 |
# File 'lib/aruba/platforms/unix_platform.rb', line 233 def which(program, path = ENV['PATH']) UnixWhich.new.call(program, path) end |
#with_replaced_environment(env = {}, &block) ⇒ Object
79 80 81 |
# File 'lib/aruba/platforms/unix_platform.rb', line 79 def with_replaced_environment(env = {}, &block) LocalEnvironment.new(self).call(env, &block) end |
#write_file(path, content) ⇒ Object
Write to file
219 220 221 |
# File 'lib/aruba/platforms/unix_platform.rb', line 219 def write_file(path, content) File.write(path, content) end |