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)


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

Returns:

  • (Boolean)


182
183
184
# File 'lib/aruba/platforms/unix_platform.rb', line 182

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

#announcerObject



52
53
54
# File 'lib/aruba/platforms/unix_platform.rb', line 52

def announcer
  Announcer
end

#builtin_shell_commandsObject



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.expand_path(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, 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
    


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_monitorObject



56
57
58
# File 'lib/aruba/platforms/unix_platform.rb', line 56

def command_monitor
  CommandMonitor
end

#command_stringObject



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_rubyObject



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_shellObject



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

Returns:

  • (Boolean)


162
163
164
# File 'lib/aruba/platforms/unix_platform.rb', line 162

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

#environment_variablesObject



40
41
42
# File 'lib/aruba/platforms/unix_platform.rb', line 40

def environment_variables
  UnixEnvironmentVariables
end

#executable?(f) ⇒ Boolean

Path is executable

Returns:

  • (Boolean)


172
173
174
# File 'lib/aruba/platforms/unix_platform.rb', line 172

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

#exist?(f) ⇒ Boolean

Path Exists

Returns:

  • (Boolean)


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 expand_path(path, base)
  File.expand_path(path, base)
end

#file?(f) ⇒ Boolean

Exists and is file

Returns:

  • (Boolean)


157
158
159
# File 'lib/aruba/platforms/unix_platform.rb', line 157

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

#filesystem_statusObject



48
49
50
# File 'lib/aruba/platforms/unix_platform.rb', line 48

def filesystem_status
  FilesystemStatus
end

#getwdObject

Get current working directory



123
124
125
# File 'lib/aruba/platforms/unix_platform.rb', line 123

def getwd
  Dir.getwd
end

#loggerObject



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.expand_path(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

Returns:

  • (Boolean)

    true

    * bin/command.sh
    

    false

    * /bin/command.sh
    * command.sh
    


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

Returns:

  • (Boolean)


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.expand_path(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, 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



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

Returns:

  • (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, 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



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