Class: Aruba::Platforms::UnixPlatform

Inherits:
Object
  • Object
show all
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

WindowsPlatform

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match?Boolean

Returns:

  • (Boolean)
[View source]

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

Returns:

  • (Boolean)
[View source]

180
181
182
# File 'lib/aruba/platforms/unix_platform.rb', line 180

def absolute_path?(path)
  Pathname.new(path).absolute?
end

#announcerObject

[View source]

50
51
52
# File 'lib/aruba/platforms/unix_platform.rb', line 50

def announcer
  Announcer
end

#builtin_shell_commandsObject

[View source]

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

[View source]

126
127
128
129
130
131
132
# File 'lib/aruba/platforms/unix_platform.rb', line 126

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

#chmod(mode, args, options) ⇒ Object

Change mode of file/directory

[View source]

150
151
152
# File 'lib/aruba/platforms/unix_platform.rb', line 150

def chmod(mode, args, options)
  FileUtils.chmod_R(mode, args, **options)
end

#command?(path) ⇒ Boolean

Check if command is relative

Returns:

  • (Boolean)

    true

    * command.sh
    

    false

    * /bin/command.sh
    * bin/command.sh
    
[View source]

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_monitorObject

[View source]

54
55
56
# File 'lib/aruba/platforms/unix_platform.rb', line 54

def command_monitor
  CommandMonitor
end

#command_stringObject

[View source]

42
43
44
# File 'lib/aruba/platforms/unix_platform.rb', line 42

def command_string
  UnixCommandString
end

#cp(src, dest) ⇒ Object

Copy file/directory

[View source]

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

[View source]

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

[View source]

74
75
76
# File 'lib/aruba/platforms/unix_platform.rb', line 74

def create_fixed_size_file(*args)
  ArubaFixedSizeFileCreator.new.call(*args)
end

#current_rubyObject

[View source]

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_shellObject

[View source]

82
83
84
# File 'lib/aruba/platforms/unix_platform.rb', line 82

def default_shell
  "bash"
end

#deprecated(msg) ⇒ Object

[View source]

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

[View source]

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

[View source]

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

[View source]

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

Returns:

  • (Boolean)
[View source]

160
161
162
# File 'lib/aruba/platforms/unix_platform.rb', line 160

def directory?(f)
  File.directory? f
end

#environment_variablesObject

[View source]

38
39
40
# File 'lib/aruba/platforms/unix_platform.rb', line 38

def environment_variables
  UnixEnvironmentVariables
end

#executable?(f) ⇒ Boolean

Path is executable

Returns:

  • (Boolean)
[View source]

170
171
172
# File 'lib/aruba/platforms/unix_platform.rb', line 170

def executable?(f)
  File.executable?(f)
end

#exist?(f) ⇒ Boolean

Path Exists

Returns:

  • (Boolean)
[View source]

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

[View source]

175
176
177
# File 'lib/aruba/platforms/unix_platform.rb', line 175

def expand_path(path, base)
  File.expand_path(path, base)
end

#file?(f) ⇒ Boolean

Exists and is file

Returns:

  • (Boolean)
[View source]

155
156
157
# File 'lib/aruba/platforms/unix_platform.rb', line 155

def file?(f)
  File.file? f
end

#filesystem_statusObject

[View source]

46
47
48
# File 'lib/aruba/platforms/unix_platform.rb', line 46

def filesystem_status
  FilesystemStatus
end

#getwdObject

Get current working directory

[View source]

121
122
123
# File 'lib/aruba/platforms/unix_platform.rb', line 121

def getwd
  Dir.getwd
end

#loggerObject

[View source]

58
59
60
# File 'lib/aruba/platforms/unix_platform.rb', line 58

def logger
  ArubaLogger
end

#mkdir(dir_name) ⇒ Object

Create directory and subdirectories

[View source]

107
108
109
110
111
# File 'lib/aruba/platforms/unix_platform.rb', line 107

def mkdir(dir_name)
  dir_name = ::File.expand_path(dir_name)

  ::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name)
end

#mv(src, dest) ⇒ Object

Move file/directory

[View source]

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

Returns:

  • (Boolean)

    true

    * bin/command.sh
    

    false

    * /bin/command.sh
    * command.sh
    
[View source]

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

Returns:

  • (Boolean)
[View source]

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

[View source]

102
103
104
# File 'lib/aruba/platforms/unix_platform.rb', line 102

def require_matching_files(pattern, base)
  ::Dir.glob(::File.expand_path(pattern, base)).sort.each { |f| require_relative f }
end

#rm(paths, options = {}) ⇒ Object

Remove file, directory + sub-directories

[View source]

114
115
116
117
118
# File 'lib/aruba/platforms/unix_platform.rb', line 114

def rm(paths, options = {})
  paths = Array(paths).map { |p| ::File.expand_path(p) }

  FileUtils.rm_r(paths, **options)
end

#simple_table(hash, opts = {}) ⇒ Object

Transform hash to a string table which can be output on stderr/stdout

[View source]

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

Returns:

  • (Boolean)
[View source]

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

[View source]

135
136
137
# File 'lib/aruba/platforms/unix_platform.rb', line 135

def touch(args, options)
  FileUtils.touch(args, **options)
end

#which(program, path = ENV["PATH"]) ⇒ Object

Resolve path for command using the PATH-environment variable

Mostly taken from here: github.com/djberg96/ptools

Parameters:

  • program (#to_s)

    The name of the program which should be resolved

  • path (String) (defaults to: ENV["PATH"])

    The PATH, a string concatenated with “:”, e.g. /usr/bin/:/bin on a UNIX-system

[View source]

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

[View source]

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

[View source]

218
219
220
# File 'lib/aruba/platforms/unix_platform.rb', line 218

def write_file(path, content)
  File.write(path, content)
end