class Minke::Helpers::Shell

Public Class Methods

new(logger) click to toggle source
# File lib/minke/helpers/shell.rb, line 4
def initialize logger
  @logger = logger
end

Public Instance Methods

execute(command, ignore_error=false) click to toggle source

Executes a shell command and returns the return status

# File lib/minke/helpers/shell.rb, line 10
def execute command, ignore_error=false
  @logger.debug command
  
  Open3.popen2e(command) do |stdin, stdout_err, wait_thr|
    while line = stdout_err.gets
      @logger.debug line
    end
    
    exit_status = wait_thr.value
    unless exit_status.success? || ignore_error == true
      raise "Error executing command: #{command}"
    end
  end
end
execute_and_return(command) click to toggle source
# File lib/minke/helpers/shell.rb, line 25
def execute_and_return command
  log = `#{command}`
  return log.strip
end
exist?(filename) click to toggle source
# File lib/minke/helpers/shell.rb, line 46
def exist? filename
  File.exist? filename
end
mktmpdir() click to toggle source
# File lib/minke/helpers/shell.rb, line 30
def mktmpdir
  Dir.mktmpdir
end
read_file(filename) click to toggle source
# File lib/minke/helpers/shell.rb, line 42
def read_file filename
  File.open(filename, 'rb') { |file| file.read }.strip
end
remove_entry_secure(dir) click to toggle source
# File lib/minke/helpers/shell.rb, line 34
def remove_entry_secure dir
  FileUtils.remove_entry_secure dir
end
write_file(filename, data) click to toggle source
# File lib/minke/helpers/shell.rb, line 38
def write_file filename, data
  File.open(filename, 'w') { |file| file.write(data) }
end