Module: Helpers

Defined in:
lib/getch/helpers.rb

Class Method Summary collapse

Class Method Details

.add_file(path, content = '') ⇒ Object



29
30
31
# File 'lib/getch/helpers.rb', line 29

def self.add_file(path, content = '')
  File.write path, content if ! File.exist? path
end

.create_dir(path, perm = 0755) ⇒ Object



25
26
27
# File 'lib/getch/helpers.rb', line 25

def self.create_dir(path, perm = 0755)
  FileUtils.mkdir_p path, mode: perm if ! Dir.exist?(path)
end

.efi?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/getch/helpers.rb', line 6

def self.efi?
  Dir.exist? '/sys/firmware/efi/efivars'
end

.exec_or_die(cmd) ⇒ Object



18
19
20
21
22
23
# File 'lib/getch/helpers.rb', line 18

def self.exec_or_die(cmd)
  _, stderr, status = Open3.capture3(cmd)
  unless status.success?
    raise "Problem running #{cmd}, stderr was:\n#{stderr}"
  end
end

.get_file_online(url, dest) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/getch/helpers.rb', line 10

def self.get_file_online(url, dest)
  URI.open(url) do |l|
    File.open(dest, "wb") do |f|
      f.write(l.read)
    end
  end
end