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)

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

Returns:

  • (Boolean)

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

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

#announcerObject


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

def announcer
  Announcer
end

#chdir(dir_name, &block) ⇒ Object

Change to directory


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

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


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

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
    

211
212
213
214
# File 'lib/aruba/platforms/unix_platform.rb', line 211

def command?(path)
  p = Pathname.new(path)
  p.relative? && p.basename == p
end

#command_monitorObject


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

def command_monitor
  CommandMonitor
end

#command_stringObject


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

def command_string
  UnixCommandString
end

#cp(args, options) ⇒ Object

Copy file/directory


139
140
141
# File 'lib/aruba/platforms/unix_platform.rb', line 139

def cp(args, options)
  FileUtils.cp_r(args, options)
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_rubyObject


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_shellObject


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

Returns:

  • (Boolean)

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

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

#environment_variablesObject


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

def environment_variables
  UnixEnvironmentVariables
end

#executable?(f) ⇒ Boolean

Path is executable

Returns:

  • (Boolean)

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

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

#exist?(f) ⇒ Boolean

Path Exists

Returns:

  • (Boolean)

164
165
166
# File 'lib/aruba/platforms/unix_platform.rb', line 164

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

#expand_path(path, base) ⇒ Object

Expand path


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

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

#file?(f) ⇒ Boolean

Exists and is file

Returns:

  • (Boolean)

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

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

#filesystem_statusObject


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

def filesystem_status
  FilesystemStatus
end

#getwdObject

Get current working directory


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

def getwd
  Dir.getwd
end

#loggerObject


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

def logger
  ArubaLogger
end

#mkdir(dir_name) ⇒ Object

Create directory and subdirectories


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

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

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

#mv(args, options) ⇒ Object

Move file/directory


144
145
146
# File 'lib/aruba/platforms/unix_platform.rb', line 144

def mv(args, options)
  FileUtils.mv(args, options)
end

#relative_command?(path) ⇒ Boolean

Check if command is relative

Returns:

  • (Boolean)

    true

    * bin/command.sh
    

    false

    * /bin/command.sh
    * command.sh
    

197
198
199
200
# File 'lib/aruba/platforms/unix_platform.rb', line 197

def relative_command?(path)
  p = ArubaPath.new(path)
  p.relative? && p.depth > 1
end

#relative_path?(path) ⇒ Boolean

Is relative path

Returns:

  • (Boolean)

184
185
186
# File 'lib/aruba/platforms/unix_platform.rb', line 184

def relative_path?(path)
  Pathname.new(path).relative?
end

#require_matching_files(pattern, base) ⇒ Object


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

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


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

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


222
223
224
# File 'lib/aruba/platforms/unix_platform.rb', line 222

def simple_table(hash, opts = {})
  SimpleTable.new(hash, opts).to_s
end

#touch(args, options) ⇒ Object

Touch file, directory


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

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


236
237
238
# File 'lib/aruba/platforms/unix_platform.rb', line 236

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


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

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